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

Viewed 32

At the moment,when clicking a box, this box is added a class with this code:

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

Now I want an addition so that the class is only added if that box does not contain a <a> link on the first level (it's children may contain links, but no children may be links). Something along the lines of this:

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

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

1 Answers
Related