Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active November 18, 2019 07:09
Show Gist options
  • Select an option

  • Save nepsilon/78cb4ac07ce108c3a3ee1e4ddf86f2e1 to your computer and use it in GitHub Desktop.

Select an option

Save nepsilon/78cb4ac07ce108c3a3ee1e4ddf86f2e1 to your computer and use it in GitHub Desktop.
Use $$() not $() to return an array of elements — First published in fullweb.io issue #69

#Use $$() not $() to return an array of elements

A tip I read on Remy Sharp’s blog.

The Devtools console gives you access to the $() function (even if you don’t include jQuery/Zepto, etc). It’s nice but doesn’t help if you need to return a collection of elements.

That’s where you can use the $$() function, also provided by the console. And the best part is that it doesn't return a NodeList but a real Array.

So you can use map, .forEach directly on it 👏.

@ujeenator
Copy link
Copy Markdown

I found it very handy and have written small NPM package to use it in production code :)

https://www.npmjs.com/package/query-alias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment