I\'m going to be running document.querySelectorAll() a whole lot, and would like a shorthand alias for it.
var queryAll = document.querySelectorAll
queryAll
A common answer is to use $
and $$
for querySelector
and querySelectorAll
. This alias mimics jQuery's one.
Example:
$ = document.querySelector.bind(document)
$$ = document.querySelectorAll.bind(document)
$('div').style.color = 'blue'
$$('div').forEach(div => div.style.background = 'orange')
div {
margin: 2px;
}
test
hello
foo