jQuery hyperlinks href value onclick
Hi, On my website I use jQuery to hook the events of elements, namely hyperlinks. As these hyperlinks only perform actions on the current page, and do not lead anywhere, I have been putting a href attribute of \"#\" in:
<a href=\"#\">My Link</a> However in some browsers this causes the page to scroll right to top which is obviously undesirable behaviour. I\'ve tried using a blank href value, or not including one, but then the mouse does not change to the hand cursor upon hovering. What should I put in there?
2 Answers
or you can do this:
<a onclick="return false;">My Link</a> Posted: MacOS 0 of 0 people found this answer helpful. Did you? Yes No
add return false to the end of your click handler, this prevents the browser default handler occurring which attempts to redirect the page:
$(\'a\').click(function() { // do stuff return false; });Or simply add the return false to the anchor itself: <a href=\"javascript:return false\">My Link</a> Bear in mind that the user will see the target of the link in the location bar when hovered over it, so I tend to favour the hash value with a return false in the handler, although this can lead to mistakes when you forget. Posted: MacOS 3 of 3 people found this answer helpful. Did you? Yes No you can use also <a onclick="return false;">My Link</a> that is very good way |
© Advanced Web Core. All rights reserved