I am novice to jquery.
Suppose i have a list of 10 "a" tags all attached to an event handler mouseover, click, mouseout respectively.
what i want to do is iterate over all the "a" elements and trigger these events using jquery trigger.
The issue i am facing is that, these events take sometime to get triggered, hence when i run the code, all i see the result change only on the last element. And not the intermediates.
$.each($("#styles a"), function(){
console.log("picked up " + $(this));
setTimeout(qwe($(this)), 2000);
});
function qwe(obj) {
console.log(obj.attr("id"));
$.when(obj.trigger("mouseover").trigger("click").trigger("mouseout"))
.then(function () {
console.log("Changing Result Value" + $("#textTag").text());
});
}
Is there way to chain these events sequentially i.e.
Second Element's events should be trigged only when the trigger action of the first elements is complete. i tried searching over SO, but mostly articles revolve around triggering only single event.
Thanks
.trigger()
doesn't return a promise, and even if it did, there's no way to know when the event handlers finish, as you could have put anything in there, and there is no callback ? – Probity