<a href="javascript:{}">

I was just exploring a template and saw that they have empty javascript:{} in href attribute. It didn’t seem to do much. Is this is just a place holder or some kind of comment that this nav works with javascript?
Please note that it was found in vav links that had unordered lists like below.



 <li class="current"><a href="javascript:{}">Home</a>
                                <ul>
                                    <li class="current"><a href="index-2.html">Simple slider</a></li>
                                    <li><a href="home_full_slider.html">Fullwidth slider</a></li>
                                </ul>
                            </li>

It is used instead of #. If # is used when clicked you go to top of window. javascript:; does not suffer from that

yeah it looks like it doesn’t do anything. I was wondering why putting this (javascript:{}) or even a # is better than keeping it empty? is it Just to make it readable?

Delete it and forget you ever saw it. Inline JS is junk anyway, and has no business sitting in place of a proper URL.

That isn’t even proper inline JavaScript. Placing JavaScript there doesn’t give it any access to information about the event that triggered the code.

It also provides a broken link for anyone without JavaScript enabled.

Thanks guys, but can you guys tell me keeping empty href is better or href with # ? Or doesn’t matter!?

If you click a link with an empty href you get an error, while clicking a link with # as the href value just jumps you to the top of the page, so the latter is better.

Edit:

Hm, I thought that was the case, but thought I’d better test it, and it wasn’t so—no error message when the href is empty. But still …

… the real question is—why have a link on your page with either of these? If the link has nowhere to go, it shouldn’t be a link. :slight_smile:

Just for temporary use. For demo templates. You know that.

I always use #, because I’ve gotten errors in the past having nothing in there.

You know that.

I don’t know how you go about designing. :stuck_out_tongue: A lot of people do have hrefs with just # in them—because the link bahavoir is controlled by JavaScript. However, that’s lousy coding, as those links are useless with JS off—which is an indication of poor coding methodology.

No, I meant you know why people use # .

Yes, but not just for demo purposes. Too often it ends up in the finished code, for the reason I mentioned.

In that case there shouldn’t be empty links… I’m with you on that.