r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

76

u/anlumo Mar 18 '19

EU citizen here. Whenever a site presents me with a tracking consent form that has >500 checkboxes to click in order to tell them to disable all tracking, I open up the dev console and do something like this:

document.querySelectorAll('.whateverClassTheCheckboxHas').forEach(cb => cb.click());

2

u/[deleted] Mar 19 '19

NodeLists do not have the Array functions on their prototype.

[].forEach.call(document.querySelectorAll('.whateverClassTheCheckboxHas'), cb => cb.click());

0

u/[deleted] Mar 19 '19

[deleted]

1

u/[deleted] Mar 19 '19

It does not. The Chrome command line API comes with $, which is not available from browser code. Also, the CLA version of $ is equivalent to document.querySelector, not querySelectorAll.

→ More replies (2)