Add a class if the clicked element does not contain <a> children

At the moment, when clicking on the drawer, a class is added to this field with this code:

$("#box").click(function(ev) {  
   $(this).addClass("new");
});

      

Now I want to add so that the class is only added if that field does not contain a link <a>

in the first level (it can have links, but none of them can be links). Something like that:

$("#box").click(function(ev) {  
   $(this).(":not(:has(a))").addClass("new");
});

      

I hope you understand my intention. Any good methods for this?

+3


source to share


1 answer


Follow these steps: -



$("#box").click(function(ev) {  
   if(!$(this).children('a').length){
     $(this).addClass("new");
   }
});

      

+3


source







All Articles