JavaScript event handling timing
I got the following problem. Could you please help?
- Have an event handler EH1 on
onload
event of body. - This event handler EH1 adds a new DOM element by calling a helper function HF1.
- Then the event handler EH1 changes the value of the new element.
- The event handler EH1 then call another helper function HF2 to calculate the output based on the new element.
In IE and Firefox开发者_开发技巧, if an alert is inserted between step 2 and 3. The output would be correct. If no alert is inserted, the output would be incorrect, as if the helper function HF2 in step 4 cannot see the value of the new element.
In Chrome or Opera, the alert does not help.
Perform your actions on DOMReady instead of onload at body.
精彩评论