Double dollar $$() vs Dollar sign $() in Chrome console behavior

后端 未结 1 2036
南笙
南笙 2020-12-15 08:33

In our project, there is a different functionality when one Dollar sign used $() in Chrome console vs two Dollar signs $$(), besides the known difference th

相关标签:
1条回答
  • 2020-12-15 09:13

    From Chrome Developer Tools documentation:

    Selecting Elements

    There are a few shortcuts for selecting elements. These save you valuable time when compared to typing out their standard counterparts.

    $() Returns the first element that matches the specified CSS selector. It is a shortcut for document.querySelector().

    $$() Returns an array of all the elements that match the specified CSS selector. This is an alias for document.querySelectorAll()

    $x() Returns an array of elements that match the specified XPath.

    When you use querySelector (or $), the result is an element or null. When you use $$, the result isn't an element but an Array which can be easily iterated over. This differs from the native querySelectorAll where it returns a NodeList which is slightly harder to go over all the entries.

    Regarding the quote: of course it works the same. See:

    Conclusion: It's useless to quote trump. You might also end insane.

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