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.

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

ameerulislam
—
2013-02-05T04:46:26Z —
#3

EricWatson said:

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?

ralphm
—
2013-02-05T06:10:07Z —
#4

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

felgall
—
2013-02-05T06:16:26Z —
#5

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.

ameerulislam
—
2013-02-05T06:39:15Z —
#6

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

ralphm
—
2013-02-05T12:45:01Z —
#7

ameerulislam said:

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.

ameerulislam
—
2013-02-05T12:46:24Z —
#8

ralph_m said:

But 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.

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

ralphm
—
2013-02-05T12:52:35Z —
#9

ameerulislam said:

Just for temporary use. For demo templates.

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. 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.

ameerulislam
—
2013-02-05T12:58:25Z —
#10

ralph_m said:

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

I don't know how you go about designing. 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 # .

ralphm
—
2013-02-05T13:00:45Z —
#11

ameerulislam said:

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.

ameerulislam
—
2013-02-05T13:06:25Z —
#12

ralph_m said:

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