-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathhas.xml
58 lines (58 loc) · 2.1 KB
/
has.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0"?>
<entry type="method" name="has" return="jQuery">
<title>.has()</title>
<signature>
<added>1.4</added>
<argument name="selector" type="String">
<desc>A string containing a selector expression to match elements against.</desc>
</argument>
</signature>
<signature>
<added>1.4</added>
<argument name="contained" type="Element">
<desc>A DOM element to match elements against.</desc>
</argument>
</signature>
<desc>Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.</desc>
<longdesc>
<p>Given a jQuery object that represents a set of DOM elements, the <code>.has()</code> method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against the descendants of the matching elements; the element will be included in the result if any of its descendant elements matches the selector.</p>
<p>Consider a page with a nested list as follows:</p>
<pre><code>
<ul>
<li>list item 1</li>
<li>list item 2
<ul>
<li>list item 2-a</li>
<li>list item 2-b</li>
</ul>
</li>
<li>list item 3</li>
<li>list item 4</li>
</ul>
</code></pre>
<p>We can apply this method to the set of list items as follows:</p>
<pre><code>
$( "li" ).has( "ul" ).css( "background-color", "red" );
</code></pre>
<p>The result of this call is a red background for item 2, as it is the only <code><li></code> that has a <code><ul></code> among its descendants.</p>
</longdesc>
<example>
<desc>Check if an element is inside another.</desc>
<code><![CDATA[
$( "ul" ).append( "<li>" +
( $( "ul" ).has( "li" ).length ? "Yes" : "No" ) +
"</li>" );
$( "ul" ).has( "li" ).addClass( "full" );
]]></code>
<css><![CDATA[
.full {
border: 1px solid red;
}
]]></css>
<html><![CDATA[
<ul><li>Does the UL contain an LI?</li></ul>
]]></html>
</example>
<category slug="traversing/filtering"/>
<category slug="version/1.4"/>
</entry>