jQuery vs document.querySelectorAll

后端 未结 12 1055
闹比i
闹比i 2020-11-28 01:28

I heard several times that jQuery\'s strongest asset is the way it queries and manipulates elements in the DOM: you can use CSS queries to create complex queries that would

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 01:45

    That's because jQuery can do much more than querySelectorAll.

    First of all, jQuery (and Sizzle, in particular), works for older browsers like IE7-8 that doesn't support CSS2.1-3 selectors.

    Plus, Sizzle (which is the selector engine behind jQuery) offers you a lot of more advanced selector instruments, like the :selected pseudo-class, an advanced :not() selector, a more complex syntax like in $("> .children") and so on.

    And it does it cross-browsers, flawlessly, offering all that jQuery can offer (plugins and APIs).

    Yes, if you think you can rely on simple class and id selectors, jQuery is too much for you, and you'd be paying an exaggerated pay-off. But if you don't, and want to take advantage of all jQuery goodness, then use it.

提交回复
热议问题