John Doe
John Doe

Reputation: 143

Automatically clicking divs present on page

I am trying to automatically click present buttons which are visible on a page, than triggering the scroll functionality after we've clicked the visible options.

I've messed around with the following code, however it didn't work in any formation I applied it.

$( ".follow-button" ).trigger( "click" );

And here's the button HTML.

<button class="follow-button btn-simple"><span class="following-txt">Following</span><span class="follow-txt">Follow</span></button>

Upvotes: 1

Views: 59

Answers (2)

brolim
brolim

Reputation: 41

You can use $(".follow-button:visible").click() to click on all visible buttons.

Upvotes: 0

WASD
WASD

Reputation: 320

for the visible buttons, now how you implemented it, checking the class and ignoring with class hidden or whatever is up to you

const buttons = document.getElementsByTagName('button');

Array.from(buttons).forEach(b => {
  b.addEventListener('click', function() {
    console.log(b.textContent);
  })
  b.click();
});
<button>asdf</button>
<button>hfdg</button>
<button>sfdf</button>
<button>ggfg</button>

Upvotes: 1

Related Questions