I am creating a list of anchor tags from a MySQL/PHP query; the anchor tags call a JavaScript function.
The 'catch 22' that I have is:
href="#"
makes the page jump to the top every time one of the anchor tags is clicked (very annoying)href="#"
means that the cursor does not change as an anchor tag is hovered over nor does that anchor tag have the appearance of an anchor tag.I know there is a way to handle this with JavaScript (possibly jQuery) but I don't recall how at the moment. However, I really prefer a simpler HTML fix (if one exists) that does not require me to get into JavaScript.
Edit:
"does not require me to get into JavaScript" == "does not require extensive changes in JavaScript."
In your javascript function you should return false
, or with jquery you can use preventDefault()
Example:
$('a').click(function(event) {
event.preventDefault();
// do something
});
Or in your case:
<a href=“#” onclick="foo();return false;">
Or change the href to javascript:void(0)
:
<a href="javascript:void(0)" onclick="foo();">
Ideally, your link degrades without javascript, so the third option will usually be avoided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With