lundi 27 mai 2019

jquery If and preventDefault [duplicate]

This question already has an answer here:

I want to preventDefault click action on the link only on the page with a specific Id. But preventDefault seems to override if condition and run on all the page.

$(function(){
if($("body#Id")){
   $("a").click(function(event) {
    event.preventDefault();
   });
 }
});

event.preventDefault() work on all page not only on body#Id.

Aucun commentaire:

Enregistrer un commentaire