I’m looking for a way to automatically “click” an item when the page loads.
I’ve tried using
$("document").ready(function() {
$("ul.galleria li:first-child img").trigger('click');
});
but it doesn’t seem to work? However, when I enter $("ul.galleria li:first-child img").trigger('click'); into Firebug’s console and run the script, it works.
Can the trigger event be used on load?
The click handler that you are trying to trigger is most likely also attached via
$(document).ready(). What is probably happening is that you are triggering the event before the handler is attached. The solution is to usesetTimeout:A delay of 10ms will cause the function to run immediately after all the
$(document).ready()handlers have been called.OR you check if the element is ready: