Returning false in the anchor tag gives an error
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 am using the following jQuery function
$('#addNew,#addNew1').click(function(){
Do I need to include this in the function, the reason I don't add the "n #" sign is because the page will move to the top of the page.
- The href attribute must point to a real URL that will work for the same purpose as JavaScript, if JavaScript fails for some reason. Work on what works .
- false, , JavaScript ( href ).
:
<a href="#" id="addNew1">ADD NEW ROW</a>
$('#addNew, #addNew1').click(function() {
// do stuff
return false;
}
Another option would be the following:
$('#addNew, #addNew1').click(function(e) {
// do stuff
e.preventDefault();
}
Usually, if you want to prevent the default action, which in this case is binding activation, you do this inside the click handler.