1

hi i have a anchor tag but I want to prevent the default behaviour using jquery. But not getting the exact solution. can you tell me what is wrong in my code?

$(document).ready(function(){
   $("a[name]").click(function(event){
     alert("As you can see, the link no longer took you to jquery.com");
     eventpreventDefault();
   });
 });

1 Answer 1

4

You are missing a dot:

eventpreventDefault();

Should be:

event.preventDefault();

You can also use return false if you wish to disable default action (of going to specified link) as well as event bubbling:

$(document).ready(function(){
   $("a[name]").click(function(event){
     alert("As you can see, the link no longer took you to jquery.com");
     return false;
   });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.