I encountered this problem today when dealing with jquery using trigger to trigger the click event of the element based on whether the cookie exists. Various debugging failed to find out the cause of the problem. Later, I searched for related issues in stackoverflow and used them. The mentioned reasons solved the problem.
The original English version is compiled as follows:
question:
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.
answer:
You can only trigger a click that jQuery has created. It's one of jQuery's cute little quirks.Use the trigger method AFTER you've established the click listener.
I used this answer to solve the problem. The main idea is: you can only trigger the click function after creating the click method with jQuery. This is jQuery. A little quirk. Use the trigger method after creating the click listener.
My code just defines the click listener after the trigger function, so the click method in the trigger cannot be executed when the page is reloaded. According to this statement, changing the position of the click listener to before the trigger trigger solved the problem