When an event handler function gets registered like this:
element.onload = function()
{
var something = Selector("identifier", "inline", 1).FadeIn("inline", 1);
CenterElement(something);
};
Is there a way to stop the execution once it starts from the inside of another handler function? Let that handler function look like this:
another.onclick = function()
{
//Cancel the execution of the above function here
document.getElementById("start").innerHTML = "Start Slideshow";
this.FadeOut();
};
Selector returns a special wrapper object that isn’t relevant for the question itself so the implementation has been omitted.
It’s quite known that it’s possible to prevent execution of a handler function by assigning undefined to the handler variable, but how to stop it if it’s already begun executing?
You’re missing an important concept here.
In javascript, there is only one thread of execution. While you might think that
onclickgets called whileonloadis executing, that is plain false.I don’t know what framework you’re using, but in jQuery you could do the following: