What is the difference direct descendent (>) vs. descendant in jQuery selectors?

后端 未结 7 691
感情败类
感情败类 2021-02-04 03:53

What\'s the difference between these two jQuery statements? They seem to do the same thing by getting all the children div tags.

$(\"#mainblock div\")

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 04:04

    $("#mainblock div") find all the divs under #mainblock

    $("#mainblock > div") only found its child

    suppose you have below HTML structure:

        

    Then

    $("#mainblock div").length = 5
    $("#mainblock > div").length = 3
    

提交回复
热议问题