make <a> link not performing the default function
I have a <a href="someaddress">
link that also has a onclick
function开发者_C百科 under a parent <div>
with id of "mention". How can I make it so that by default, when user clicks the <a>
link it will not redirect to the webpage but it will do the onclick function?
I want to still have href because in case if user's javascript doesn't work, at least they can still go to the link.
...or return false;
on your javascript call.
insert e.preventDefault() into your onclick function if it already exists, e.g.
$("#mention a").click(function(e) {
e.preventDefault();
// whatever is not default
});
You could also use return false;
.
onclick="return false;"
is a way to make an <a>
tag not actually do anything on click.
EDIT
i had onlick
, obv. it was supposed to be onclick
Use event.preventDefault()
.
Here's an example: http://jsfiddle.net/FishBasketGordo/2R2Ud/.
精彩评论