Can I combine a variable and a selector in Jquery?

前端 未结 3 2101
-上瘾入骨i
-上瘾入骨i 2021-02-15 14:12

Say I have this HTML:

top
middle
bottom
middle
3条回答
  •  灰色年华
    2021-02-15 15:00

    Use

    $('.middle', $top)
    

    or

    $top.find('.middle')
    

    You could also have simply combined the selectors, which are strings, with

    $($top.selector + ' .middle')
    

    but this would only be slower and less readable...

提交回复
热议问题