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
$("a.add-span").click(function() {
$("li").each(function(index) {
if ($(this).children('span').length === 0){
$(this).append('new span<\/span>');
}
})
})
With children() method, the length property is used to check whether or not a span already exits and if it doesn't, one is added/appended.
More Info: