mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fix #13797: .is with single-node context
This commit is contained in:
parent
85b3c82445
commit
4f786ba4d2
@ -58,14 +58,16 @@ jQuery.fn.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
is: function( selector ) {
|
is: function( selector ) {
|
||||||
return !!selector && (
|
return !!winnow(
|
||||||
typeof selector === "string" ?
|
this,
|
||||||
|
|
||||||
// If this is a positional/relative selector, check membership in the returned set
|
// If this is a positional/relative selector, check membership in the returned set
|
||||||
// so $("p:first").is("p:last") won't return true for a doc with two "p".
|
// so $("p:first").is("p:last") won't return true for a doc with two "p".
|
||||||
rneedsContext.test( selector ) ?
|
typeof selector === "string" && rneedsContext.test( selector ) ?
|
||||||
jQuery( selector, this.context ).index( this[0] ) >= 0 :
|
jQuery( selector ) :
|
||||||
jQuery.filter( selector, this ).length > 0 :
|
selector || [],
|
||||||
this.filter( selector ).length > 0 );
|
false
|
||||||
|
).length;
|
||||||
},
|
},
|
||||||
|
|
||||||
closest: function( selectors, context ) {
|
closest: function( selectors, context ) {
|
||||||
|
@ -141,16 +141,22 @@ test("is() with :has() selectors", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("is() with positional selectors", function() {
|
test("is() with positional selectors", function() {
|
||||||
expect(24);
|
expect(27);
|
||||||
|
|
||||||
var isit = function(sel, match, expect) {
|
var
|
||||||
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
|
posp = jQuery(
|
||||||
|
"<p id='posp'><a class='firsta' href='#'><em>first</em></a>" +
|
||||||
|
"<a class='seconda' href='#'><b>test</b></a><em></em></p>"
|
||||||
|
).appendTo( "#qunit-fixture" ),
|
||||||
|
isit = function( sel, match, expect ) {
|
||||||
|
equal(
|
||||||
|
jQuery( sel ).is( match ),
|
||||||
|
expect,
|
||||||
|
"jQuery('" + sel + "').is('" + match + "')"
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery(
|
isit( "#posp", "p:last", true );
|
||||||
"<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>"
|
|
||||||
).appendTo( "#qunit-fixture" );
|
|
||||||
|
|
||||||
isit( "#posp", "#posp:first", true );
|
isit( "#posp", "#posp:first", true );
|
||||||
isit( "#posp", "#posp:eq(2)", false );
|
isit( "#posp", "#posp:eq(2)", false );
|
||||||
isit( "#posp", "#posp a:first", false );
|
isit( "#posp", "#posp a:first", false );
|
||||||
@ -179,6 +185,9 @@ test("is() with positional selectors", function() {
|
|||||||
isit( "#posp em", "#posp a em:eq(2)", false );
|
isit( "#posp em", "#posp a em:eq(2)", false );
|
||||||
|
|
||||||
ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" );
|
ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" );
|
||||||
|
|
||||||
|
ok( jQuery( posp[0] ).is("p:last"), "context constructed from a single node (#13797)" );
|
||||||
|
ok( !jQuery( posp[0] ).find("#firsta").is("a:first"), "context derived from a single node (#13797)" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("index()", function() {
|
test("index()", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user