Okay I have list items, some have a span, some not.
On my event I want to add the span when they don\'t have any yet.
has() works fine, but
The accepted answer works well, if you don't want to filter out only those elements which do have the spans as direct children.
As the :has() and the .has() loop over all descendants, not just the children.
In that case, you have to use a function
$("li").not(function() {
// returns true for those elements with at least one span as child element
return $(this).children('span').length > 0
}).each(function() { /* ... */ })