jQuery selector :link not working with $.is() or $.filter()...?
It seems like the selector ":link"
is not supported by jQuery's filter()
开发者_高级运维or is()
function. For instance, if I evaluate $(":link")
on a page it returns multiple links. If I evaluate $(":link").filter(":link")
or $(":link").is(":link")
, an error is thrown. The error message is "Syntax error, unrecognized expression: link".
Is this by design? Do filter()
and is()
not support the same CSS selectors is jQuery does generally? Is there documentation as to the difference?
Patrick commented that jQuery defaults in some cases to the browser's built in querySelector or querySelectorAll where it exists. So, :link
appears to work on some browsers, but I wouldn't suggest using it as it seems to produce wonderfully bizarre results.
<a href="www.foo.com">Hello</a>
alert($("a").is("a")); // do it this way
// changes the anchor's CSS, but does not return the length
alert($(":link").css('background','yellow').length);
Demo: http://jsfiddle.net/xWPw7/4
精彩评论