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?
答案 0 :(得分:3)
如下所示: -
$("#box").click(function(ev) {
if(!$(this).children('a').length){
$(this).addClass("new");
}
});