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

后端 未结 7 554
感情败类
感情败类 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:15

    $("#mainblock div")
    

    This one target all DIVs inside "#mainblock" not matter it's direct child of "#mainblock", or child of child of main block or so on.

    $("#mainblock > div")
    

    This will target only direct child DIVs of "#mainblock" and ignore other DIVs. This one is faster then above in case you have only direct childs. Because it's not try to find inside other elements of childs.

提交回复
热议问题