jQuery first child of “this”

<p>If you want to apply a selector to the context provided by an existing jQuery set, try the find() function:</p><p><span ><strong><span >element.find(&quot;&gt;:first-child&quot;).toggleClass(&quot;redClass&quot;);</span></strong></span></p><p>Jørn Schou-Rode noted that you probably only want to find the first direct descendant of the context element, hence the child selector (&gt;). He also points out that you could just as well use the children() function, which is very similar to find() but only searches one level deep in the hierarchy (which is all you need...):</p><p><span ><strong>element.children(&quot;:first&quot;).toggleClass(&quot;redClass&quot;);</strong></span></p>
RangeMem:204.32 KB
返回顶部 留言