I'm figuring out why this simple script is not working:
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('.next_button a').trigger('click');
});
noConflict
is necessary because I also load prototype/scriptaculous in this page.
If I replace .trigger('click')
with another function (es: .css(...)
this works well. Only triggering seems to go broken.
How can I simulate an anchor click via jquery? Check this link and see this answer by Stevanicus.
$('a#swaswararedirectlink')[0].click();
You can only trigger a click that jQuery has created. It's one of jQuery's cute little quirks.
I thought that this demo would not work but it does (Chrome 12). It willalert
two messages, one for each click event. One is created by jQuery and one is native but I thought that only jQuery events could be triggered.Edit: Yes the
click
does not followhref
.Edit 2: So the event you want to manually trigger is actually an event created by a Prototype carousel plugin. For the code below I am assuming it is this one. If that is the case, why can't you just use fire the event using Prototype or natively… like this:
There are two examples in this demo of event firing (one is commented out but you can switch for the same result). One is from Trigger an event with Prototype which uses
event.simulate.js
and one using thefakeClick()
function from How can I simulate a click to an anchor tag?. Either of which is working for me in Chrome 12.as what Gary has answered. the code below will not work.
but this will.. :)