javascript auto click several buttons with same class at once

Discussion in 'HTML & JavaScript' started by dalooroorl, Oct 22, 2014.

  1. dalooroorl

    dalooroorl Newbie

    Joined:
    Sep 15, 2013
    Messages:
    15
    Likes Received:
    0
    goo.gl/ MNR1ZB

    as u see, i want to click the unfollow buttons at once, i did it with a code, but it only clicks on the first one...

    can any1 help me?
     
  2. Conor

    Conor Elite Member

    Joined:
    Nov 7, 2012
    Messages:
    3,618
    Likes Received:
    6,078
    Gender:
    Male
    Location:
    South Africa
    Does this not work? Replace "selector" with the class of the unfollow buttons.

    Code:
    jQuery(document).ready(function($) {
    $("selector").click();
    });
    
     
  3. dalooroorl

    dalooroorl Newbie

    Joined:
    Sep 15, 2013
    Messages:
    15
    Likes Received:
    0
    ty for reply bro, but that was the code i used :D
     
  4. Conor

    Conor Elite Member

    Joined:
    Nov 7, 2012
    Messages:
    3,618
    Likes Received:
    6,078
    Gender:
    Male
    Location:
    South Africa
    Hmm, you could make an iMacro. It might be an easier solution.
     
  5. ChrisX

    ChrisX Jr. VIP Jr. VIP

    Joined:
    Oct 8, 2011
    Messages:
    293
    Likes Received:
    144
    Gender:
    Male
    Home Page:
    Try this:
    Code:
    $("selector").each(function(){click()});
     
  6. dalooroorl

    dalooroorl Newbie

    Joined:
    Sep 15, 2013
    Messages:
    15
    Likes Received:
    0
    didn't worked :(
     
  7. dalooroorl

    dalooroorl Newbie

    Joined:
    Sep 15, 2013
    Messages:
    15
    Likes Received:
    0
    someone can help me?
     
  8. member8200

    member8200 Regular Member

    Joined:
    Aug 9, 2014
    Messages:
    475
    Likes Received:
    33
    try this one.


    <script>
    $(document).ready(function(){

    $(".ClassSelectorHere").click(function(){

    //do something here

    });

    });
    <script>



    hope this helps. btw, don't forget the jquery library. :)
     
    Last edited: Oct 28, 2014
  9. μελαγχολία

    μελαγχολία Regular Member

    Joined:
    Jul 16, 2010
    Messages:
    208
    Likes Received:
    26
    Location:
    Somewhere over the rainbow
    You have to put a dot in front of the class name in the selector to work, so no $('classname') but $('.classname'), maybe this was the problem? Also, jQuery needs to be included in the web page for this to work.
     
  10. somedevil

    somedevil Jr. VIP Jr. VIP

    Joined:
    Sep 9, 2009
    Messages:
    1,098
    Likes Received:
    516
    Location:
    Dark side of the moon..
    Home Page:
    Here is a iMacro tutorial that might help you make your own custom one.
     
  11. uncommonbg

    uncommonbg Regular Member

    Joined:
    Jul 15, 2014
    Messages:
    233
    Likes Received:
    40
    Location:
    Neverland
    That way will work with jQuery, but the title says Javascript so I'm a little confused.
    If you need It in javascript, here is the code:
    Code:
    function clickAllButtons() {
            var allButtons = document.getElementsByClassName("yourItemsClass");
            for(i=0;i<allButtons.length;i++) {
                   // do whatever you wanna do here
                }
            }
        }
        window.onload = clickAllButtons;
    
     
  12. dalooroorl

    dalooroorl Newbie

    Joined:
    Sep 15, 2013
    Messages:
    15
    Likes Received:
    0
    ty all, but nothing works.

    the button code:

    Code:
    <a class="unfollow-button" href="unfollow?url=xxx"></a>
    EDIT: I find out how! with this code:

    Code:
    javascript:e=document.getElementsByClassName('unfollow-button');for(i=0;i<e.length;i++){e[i].click();}void(0);
    Thank you all!
     
    Last edited: Oct 29, 2014