4 ms·
window.$ = document.querySelectorAll
by xg15 2y ago
window.$ = document.querySelectorAll
- dsego 2y agoBut it doesn't do chaining and you have to loop through elements to do anything with them.
- Spivak 2y agoI'm always surprised that an API that is defined by matching 0-n dom elements doesn't return a container that by default maps over them list monad style.
- freeone3000 2y agoThere’s a fairly small polyfill that makes a DOMNodeList have the same functions as Array.
- jasonjayr 2y agoAre the various browser JS implementations clever enough not to make a new Object for Array.from(DOMNodeList) ?
- pwdisswordfishz 2y agoUncaught TypeError: 'querySelectorAll' called on an object that does not implement interface Document.
- xg15 2y agoDamn, you're right, sorry. window.$ = (x => document.querySelectorAll(x))
- roebk 2y agowindow.$ = document.querySelectorAll.bind(document)
- deleted 2y ago[deleted]
- ComputerGuru 2y agoThe wrong syntax notwithstanding, this doesn't let you recursively use querySelector(All), e.g. to find children of a node like document.querySelector("#foo").querySelectorAll(".bar")
- xg15 2y agoI know, it was a bit of a joke. But I think the OP's jQuery replacement is also dropping features in the service of a small footprint. So this was my 80/20 contribution to the "smallest jQuery replacement" problem ;)