Ran Tang
Ran Tang

Reputation: 241

JavaScript event handling timing

I got the following problem. Could you please help?

  1. Have an event handler EH1 on onload event of body.
  2. This event handler EH1 adds a new DOM element by calling a helper function HF1.
  3. Then the event handler EH1 changes the value of the new element.
  4. 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.

Upvotes: 0

Views: 116

Answers (1)

Peeter
Peeter

Reputation: 9382

Perform your actions on DOMReady instead of onload at body.

Upvotes: 1

Related Questions