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.
You need to trigger the default click method, not the one by jQuery. This can be done by adding the default click option within a click event of jQuery using this . This is how the JavaScript looks. It basically creates the event when the DOM is ready, and clicks it intermediately, thus following the link.
trigger( "click" ); As of jQuery 1.3, . trigger() ed events bubble up the DOM tree; an event handler can stop the bubbling by returning false from the handler or calling the . stopPropagation() method on the event object passed into the event.
jQuery submit() Method The submit event occurs when a form is submitted. This event can only be used on <form> elements. The submit() method triggers the submit event, or attaches a function to run when a submit event occurs.
The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.
How can I simulate an anchor click via jquery? Check this link and see this answer by Stevanicus.
$('a#swaswararedirectlink')[0].click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With