File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change 2137
2137
**/
2138
2138
function descendantOf_DOM ( element , ancestor ) {
2139
2139
element = $ ( element ) , ancestor = $ ( ancestor ) ;
2140
+ if ( ! element || ! ancestor ) return false ;
2140
2141
while ( element = element . parentNode )
2141
2142
if ( element === ancestor ) return true ;
2142
2143
return false ;
2143
2144
}
2144
2145
2145
2146
function descendantOf_contains ( element , ancestor ) {
2146
2147
element = $ ( element ) , ancestor = $ ( ancestor ) ;
2148
+ if ( ! element || ! ancestor ) return false ;
2147
2149
// Some nodes, like `document`, don't have the "contains" method.
2148
2150
if ( ! ancestor . contains ) return descendantOf_DOM ( element , ancestor ) ;
2149
2151
return ancestor . contains ( element ) && ancestor !== element ;
2150
2152
}
2151
2153
2152
2154
function descendantOf_compareDocumentPosition ( element , ancestor ) {
2153
2155
element = $ ( element ) , ancestor = $ ( ancestor ) ;
2156
+ if ( ! element || ! ancestor ) return false ;
2154
2157
return ( element . compareDocumentPosition ( ancestor ) & 8 ) === 8 ;
2155
2158
}
2156
2159
Original file line number Diff line number Diff line change @@ -867,6 +867,9 @@ suite('DOM', function () {
867
867
assert ( ! $ ( 'ancestor' ) . descendantOf ( $ ( 'child' ) ) ,
868
868
'#ancestor should not be descendant of child' ) ;
869
869
870
+ assert ( ! $ ( 'child' ) . descendantOf ( $ ( 'non-existent-thing' ) ) , 'cannot be a descendant of a non-element' ) ;
871
+ assert ( ! Element . descendantOf ( 'non-existent-thing' , $ ( 'ancestor' ) ) , 'non-element cannot be a descendant of anything' ) ;
872
+
870
873
assert ( $ ( 'great-grand-child' ) . descendantOf ( 'ancestor' ) , 'great-grand-child < ancestor' ) ;
871
874
assert ( $ ( 'grand-child' ) . descendantOf ( 'ancestor' ) , 'grand-child < ancestor' ) ;
872
875
assert ( $ ( 'great-grand-child' ) . descendantOf ( 'grand-child' ) , 'great-grand-child < grand-child' ) ;
You can’t perform that action at this time.
0 commit comments