1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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 Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,361
    Likes Received:
    5,423
    Gender:
    Male
    Location:
    South Africa
    Home Page:
    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 Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,361
    Likes Received:
    5,423
    Gender:
    Male
    Location:
    South Africa
    Home Page:
  5. ChrisX

    ChrisX Jr. VIP Jr. VIP Premium Member

    Joined:
    Oct 8, 2011
    Messages:
    229
    Likes Received:
    124
    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:
    469
    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. μελαγχολία

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

    Joined:
    Jul 16, 2010
    Messages:
    198
    Likes Received:
    25
    Location:
    Somewhere over the rainbow
    Home Page:
    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,012
    Likes Received:
    493
    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:
    228
    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