Skip to content

Instantly share code, notes, and snippets.

@eviltester
Created August 16, 2018 06:00
Show Gist options
  • Save eviltester/c29f2add0fc713a5185261a3f11a00fc to your computer and use it in GitHub Desktop.
Save eviltester/c29f2add0fc713a5185261a3f11a00fc to your computer and use it in GitHub Desktop.
find a bunch of stuff on the page and click on them
var divs = document.querySelectorAll('.button'); [].forEach.call(divs, function(div) { div.click();});
@eviltester
Copy link
Author

a 'for' loop version would be:

var divs = document.querySelectorAll('.button');
for (x = divs.length - 1; x >= 0; x--) {
   divs[x].click();
}

@eviltester
Copy link
Author

For loop which doesn't work in reverse:

var divs = document.querySelectorAll('input.toggle');
for (x = 0; x < divs.length; x++) {
   divs[x].click();
}

Working in reverse can be useful when you are 'deleting' or the length changes over time, here my action doesn't change the length so I can start at the top and work down.

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