Arturas Rosenbacher Arturas Rosenbacher - 5 months ago 8
Javascript Question

Click all buttons via JS

var inputs = document.getElementsByClassName('minds-subscribe-button');

for (var i=0; i<inputs.length;i++)
{
inputs[i].click();
}


That code works to click both buttons -
<button class="minds-subscribe-button">
and
<button class="minds-subscribe-button subscribed">


I don't want to click the buttons that have
"minds-subscribe-button subscribed"
, only
"minds-subscribe-button"
.

Answer

Inside your for loop, you could execute:

if(!$(inputs[i]).hasClass("subscribed")){
   inputs[i].click();
}

It will verify if the input hasn't the class subscribed. If it's true, then click.

Comments