jQuery class within class selector

前端 未结 2 1329
别那么骄傲
别那么骄傲 2020-12-07 20:52

how do I find the inner div here?

$container.fi

相关标签:
2条回答
  • 2020-12-07 21:03

    For this html:

    <div class="outer">
         <div class="inner"></div>
    </div>
    

    This selector should work:

    $('.outer > .inner')
    
    0 讨论(0)
  • 2020-12-07 21:20

    is just going to look for a div with class="outer inner", is that correct?

    No, '.outer .inner' will look for all elements with the .inner class that also have an element with the .outer class as an ancestor. '.outer.inner' (no space) would give the results you're thinking of.

    '.outer > .inner' will look for immediate children of an element with the .outer class for elements with the .inner class.

    Both '.outer .inner' and '.outer > .inner' should work for your example, although the selectors are fundamentally different and you should be wary of this.

    0 讨论(0)
提交回复
热议问题