control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/has.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
2.0 KiB
JSON

{"name":"has","type":"method","title":".has()","deprecated":null,"removed":null,"desc":"Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.","categories":["traversing/filtering","version/1.4"],"entries":[{"return":"jQuery","signatures":[{"added":"1.4","argument":{"desc":"A string containing a selector expression to match elements against.","name":"selector","type":"String"}},{"added":"1.4","argument":{"desc":"A DOM element to match elements against.","name":"contained","type":"Element"}}],"examples":{"desc":"Check if an element is inside another.","code":"\n$( \"ul\" ).append( \"<li>\" +\n ( $( \"ul\" ).has( \"li\" ).length ? \"Yes\" : \"No\" ) +\n \"</li>\" );\n$( \"ul\" ).has( \"li\" ).addClass( \"full\" );\n","css":"\n .full {\n border: 1px solid red;\n }\n","html":"\n<ul><li>Does the UL contain an LI?</li></ul>\n"},"longdesc":"\n <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>\n <p>Consider a page with a nested list as follows:</p>\n <pre><code>\n &lt;ul&gt;\n &lt;li&gt;list item 1&lt;/li&gt;\n &lt;li&gt;list item 2\n &lt;ul&gt;\n &lt;li&gt;list item 2-a&lt;/li&gt;\n &lt;li&gt;list item 2-b&lt;/li&gt;\n &lt;/ul&gt;\n &lt;/li&gt;\n &lt;li&gt;list item 3&lt;/li&gt;\n &lt;li&gt;list item 4&lt;/li&gt;\n&lt;/ul&gt;\n </code></pre>\n <p>We can apply this method to the set of list items as follows:</p>\n <pre><code>\n$( \"li\" ).has( \"ul\" ).css( \"background-color\", \"red\" );\n </code></pre>\n <p>The result of this call is a red background for item 2, as it is the only <code>&lt;li&gt;</code> that has a <code>&lt;ul&gt;</code> among its descendants.</p>\n "}]}