aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2007-08-21 07:33:52 +0000
committerJohn Resig <jeresig@gmail.com>2007-08-21 07:33:52 +0000
commit46e770352a9d68fe72a2cf59fc2d18fe61669730 (patch)
treec83ba508ca895f0a1b6c3f933405cae80500cd31
parentc8bd6e0a4aef14ad4808a63fc106849918ea4666 (diff)
downloadjquery-46e770352a9d68fe72a2cf59fc2d18fe61669730.tar.gz
jquery-46e770352a9d68fe72a2cf59fc2d18fe61669730.zip
Added the new :has() selector (Bug #1521)
-rw-r--r--src/selector/selector.js5
-rw-r--r--src/selector/selectorTest.js3
2 files changed, 6 insertions, 2 deletions
diff --git a/src/selector/selector.js b/src/selector/selector.js
index f2c224a02..cf231111e 100644
--- a/src/selector/selector.js
+++ b/src/selector/selector.js
@@ -53,7 +53,10 @@ jQuery.extend({
image: "'image'==a.type",
reset: "'reset'==a.type",
button: '"button"==a.type||jQuery.nodeName(a,"button")',
- input: "/input|select|textarea|button/i.test(a.nodeName)"
+ input: "/input|select|textarea|button/i.test(a.nodeName)",
+
+ // :has()
+ has: "jQuery.find(m[3],a).length"
},
"[": "jQuery.find(m[2],a).length"
},
diff --git a/src/selector/selectorTest.js b/src/selector/selectorTest.js
index 7644fbea8..7a4789a80 100644
--- a/src/selector/selectorTest.js
+++ b/src/selector/selectorTest.js
@@ -197,7 +197,7 @@ test("pseudo (:) selectors", function() {
});
test("basic xpath", function() {
- expect(16);
+ expect(17);
ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
ok( jQuery.find("//div", q("main")[0])[0] = q("foo")[0], "All Relative (#main//div)" );
t( "All P Elements", "//p", ["firstp","ap","sndp","en","sap","first"] );
@@ -213,6 +213,7 @@ test("basic xpath", function() {
t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","iframe","lengthtest","table","fx-queue","fx-tests","sndp","en","sap"] );
t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","iframe","lengthtest","table","fx-queue","fx-tests","sndp","en","sap"] );
t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
+ t( "Has Children - :has()", "//p:has(a)", ["firstp","ap","en","sap"] );
$("#foo").each(function() {
isSet( $("/p", this).get(), q("sndp", "en", "sap"), "Check XPath context" );