SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    having a link which runs a js function (acceptable to have no href?)

    question: if you want a link which simply runs a js function is it acceptable to have no href? the problem with this is the cursor doesnt change when you hover over, but if you put # as the href it jumps to the top of the screen which is sometimes unacceptable. what it the best solution to this? granted you could do event handling behind the scenes and just intercept the clicks and prevent the href from going anywhere, but sometimes you just want to stick an onclick on the anchor tag!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you can put "javascript:;" as the href. I don't like doing that, but it works.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Leeds, UK
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it have to be a link? using a <span> instead is slightly better, but still you should really be handling this seperately from your HTML.

    eg as a span.

    Code:
    <span onclick="someFunc();return false;" style="text-decoration:underline;cursor:pointer">I'm intrusive :)</span>
    Last edited by NakedIntruder; Jul 17, 2006 at 04:07. Reason: forgot the cursor style

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    London, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you do this, you get the right cursor and no # in the URL.
    <a href="#" onclick="foo(); return false;">Run foo()</a>

  5. #5
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers, and of course it is better to abstract this, however im lazy and when at work its just a case of churning things out as quickly as possible.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    Leeds, UK
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *tut tut* (just kidding)


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
  •