Reputation: 36829
I have the following statement
<a href="javascript: return false;" id="addNew1">ADD NEW ROW</a>
If I click on this I get the following error in my browser.
return not in function
I use the following JQuery function
$('#addNew,#addNew1').click(function(){
Do I need to include this in the function, the reason I do not add 'n # sign in is because the the page jumps to the top of the page.
Upvotes: 3
Views: 6511
Reputation: 185883
This works:
<a href="#" id="addNew1">ADD NEW ROW</a>
$('#addNew, #addNew1').click(function() {
// do stuff
return false;
}
Another option would be this:
$('#addNew, #addNew1').click(function(e) {
// do stuff
e.preventDefault();
}
Usually, if you want to prevent the default action, which in this case is the activation of the anchor, you do it inside the click handler.
Upvotes: 4
Reputation: 943134
Upvotes: 6
Reputation: 61729
<a href="#" onclick="return false;" id="addNew1">ADD NEW ROW</a>
Upvotes: 7