Skip to content

JavaScript – Click all buttons with Class Name after 5 seconds (Twitter)

I’ve been trying to get my script to work for ages now, and it just won’t have it! I’m trying to click all the ‘unfollow button’s on my Twitter/Following page after 5 seconds. Here’s my code without the setInterval function:

var buttonArray = document.getElementsByClassName('w-button-common w-button-unfollow'); for(var a=0;a<buttonArray.length;a++){ buttonArray[0].click(); } 

Here’s Twitters HTML DOM code for the unfollow buttons:

    <span class="w-button-common w-button-unfollow"><input alt="Follow" src="https://ma.twimg.com/twitter-mobile/97bb0ca1daa74ae65fd470b1961897275eb91579/images/sprites/followchecked.gif" type="image"></span>
  <input type="hidden" name="scribe_item" value="description=list&amp;id=1875185790&amp;item_type=3">
</form>
</td>

I’d be so appreciated if someone could amend my code! Thank you so much in advance!

Answer

Change buttonArray[0].click() to buttonArray[a].click().