6

I'm trying to trigger a click on multiple elements with the same class but when i do so the first element only get clicked and not the others, frankly I'm trying to make likes to all ask.fm profile answers by using the console of firefox so this is what i did

$('.like').trigger('click');

but i realized that only the first element (answer) get clicked so i did something else

$('.like').each(function(){$(this).trigger('click');}) 

but the problem still exist, os what am i doing wrong here !!

Edit: The html code

all answers got this element in it

<a class="like hintable" hint="Like" href="#" onclick="Like.quickLike(128332156539, &quot;mo7am_rs&quot;, &quot;/likes/am77r/question/128332156539/add&quot;); return false;" style="display:block"></a>

and i want to click this element in all answers element

4
  • 2
    add your html code here. it might help us too Commented May 25, 2015 at 12:49
  • trigger executes all handlers and behaviors attached to the matched elements, or in other words all elements with that class, so the issue isn't trigger, it's you, obviously! Commented May 25, 2015 at 12:50
  • Also add your .like click handler code Commented May 25, 2015 at 12:50
  • Show the function you are triggering from $('.like') elements .. Commented May 25, 2015 at 12:56

2 Answers 2

11

Frankly I'm trying to make likes to all ask.fm profile answers

Your code should work, so, probably they're ignoring/blocking two too consecutive clicks to prevent bots and missclicks.

A workaround to this would be adding a sleep to it (you should adjust the sleep value, because it depends on their secret configured threshold).

The following code would try a click after each 10 seconds:

var sleep = 0;
$('.like').each(function(){
    var likeElement = $(this);
    setTimeout(function() {
        likeElement.trigger('click');
    }, sleep);
    sleep += 10000;
});

Please, also verify if that practice is compliant to the site's policy.

Sign up to request clarification or add additional context in comments.

4 Comments

i forgot to mention that i did try to delay the clicking procedure and it didn't work neither your code did :(
@MOHAMMADRASIM Try it with a larger sleep. Eg. 10000 (10 seconds, see updated answer). Or another even larger, eg. 100000 (100 seconds. - as I said: you should adjust the sleep value, because it will depend on their secret configured threshold)
I've increased the timeout in your code but your code doesn't even click the first element
@MOHAMMADRASIM You're right. Please, see my updated code. I've fixed a closure issue. It should work now :) Thanks for pointing this out.
2

Try this : write a click handler for all like element and then trigger click event on it.

$(function(){
  //register a handler
  $( ".like" ).on( "click", function() {
   alert( $( this ).text() );
  });
  //trigger click 
  $( ".like" ).trigger( "click" );
});

JSFiddle Demo

2 Comments

ok, your code works but i have to click an alert box each time and that's not what i wanted to do, i wanted the code to click the elements without the intervention of the user
I kept the alert box to show that every div is getting clicked by showing its text, you can remove that and put your logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.