I want to load an image and some other actions after I click a certain DOM element, but I want to load them AFTER the clicking action finished.
Here is a code example:
$("#message_link").click(function(){ if (some_conditions...){ $("#header").append("<div><img alt=\"Loader\"src=\"/images/ajax-loader.gif\" /></div>"); } });
The problem is that the if condition executes before the click action have finished(Or at least that is my impression). I need that the If condition executes after the click action has finished. Can some one please tell me a solution?
Thanks :)
$("document"). ready(function() { setTimeout(function() { $("ul. galleria li:first-child img"). trigger('click'); },10); });
The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.
So onclick creates an attribute within the binded HTML tag, using a string which is linked to a function. Whereas . click binds the function itself to the property element.
setTimeout
may help out here
$("#message_link").click(function(){ setTimeout(function() { if (some_conditions...){ $("#header").append("<div><img alt=\"Loader\"src=\"/images/ajax-loader.gif\" /></div>"); } }, 100); });
That will cause the div to be appended ~100ms after the click event occurs, if some_conditions are met.
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