SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

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

    HTML Code:
     <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>

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    It is used instead of #. If # is used when clicked you go to top of window. javascript:; does not suffer from that

  3. #3
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    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?

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Delete it and forget you ever saw it. Inline JS is junk anyway, and has no business sitting in place of a proper URL.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, but can you guys tell me keeping empty href is better or href with # ? Or doesn't matter!?

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ameerulislam View Post
    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.

  8. #8
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    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.

  9. #9
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ameerulislam View Post
    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.

  10. #10
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    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 # .

  11. #11
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by ameerulislam View Post
    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.

  12. #12
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •