When used with the child selector >
, the two variants of jQuery's "has" behave differently.
Take this HTML:
<div>
<span>Text</span>
</div>
Now:
$("div:has(>span)");
would return it, while:
$("div").has(">span");
would not. Is it a bug or a feature? Compare here: http://jsfiddle.net/aC9dP/
EDIT: This may be a bug or at least undocumented inconsistent behavior.
Anyway, I think it would be beneficial to have the child selector consistently work as an unary operator. It enables you to do something that otherwise would require a custom filter function — it lets you directly select elements that have certain children:
$("ul:has(>li.active)").show(); // works
$("ul").has(">li.active)").show(); // doesn't work, but IMHO it should
as opposed to:
$("ul").filter(function () {
return $(this).children("li.active").length > 0;
}).show();
I've opened a jQuery ticket (7205) for this.