querySelector/querySelectorAll shims that enable the use of :scope
BSD-2-CLAUSE License
querySelector/querySelectorAll shims that enable the use of :scope
:scope
, when combined with the immediate child selector >
, lets you query for elements that are immediate children of a HTMLElement instance.
For instance, you might want to find all list items of an unordered list that is an immediate child of node
:
var listItems = node.querySelector(':scope > ul > li');
This is effectively equivalent to using jQuery's find()
:
var $listItems = $(node).find('> ul > li');
See the Mozilla Developer Network article on :scope for more information.
Simply include the JavaScript file:
<script src="scopeQuerySelectorShim.js"></script>
:scope
support before inserting itself, and uses it if it's available
querySelector
call against the the parent if notquerySelectorAll
returns a NodeList, just like the native methodHTMLElement.prototype
Document.prototype
's querySelector
/querySelectorAll
methods are not shimmed
:scope
is not relevant at the document leveldocument.documentElement.querySelector
instead without :scope
To run the tests:
npm install
grunt test
scopedQuerySelectorShim is licensed under the permissive BSD license.