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, "mo7am_rs", "/likes/am77r/question/128332156539/add"); return false;" style="display:block"></a>
and i want to click this element in all answers element
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, "mo7am_rs", "/likes/am77r/question/128332156539/add"); return false;" style="display:block"></a>
and i want to click this element in all answers element
Share Improve this question edited May 25, 2015 at 12:56 MOHAMMAD RASIM asked May 25, 2015 at 12:48 MOHAMMAD RASIMMOHAMMAD RASIM 4051 gold badge7 silver badges18 bronze badges 4- 2 add your html code here. it might help us too – Coding Enthusiast 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'ttrigger
, it's you, obviously! – adeneo Commented May 25, 2015 at 12:50 -
Also add your
.like
click handler code – Tushar Commented May 25, 2015 at 12:50 -
Show the function you are triggering from
$('.like')
elements .. – Qarib Haider Commented May 25, 2015 at 12:56
2 Answers
Reset to default 11Frankly 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 pliant to the site's policy.
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