Dejo Dekic
Dejo Dekic

Reputation: 2126

For loop works faulty in firefox?

I have a simple for loop inside jQuery but it is not working fine in Firefox.

Problem: It writes my variable fine but if you look at the Firefox tab it says

Connecting...

all the time.

Also if I check my script with Firebug it says:

No Javascript on this page

although it writes my variable.

What I am doing wrong here? Fiddle here

$(document).ready(function(){
      var i=0;
      for(i=0;i<=3;i++) {
          document.write(i);
      }
      //alert("working");
});

Upvotes: 0

Views: 131

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117354

Never use write() after the document has finished loading, it will overwrite the complete document(including scripts)

But however, when the issue is the fact that the (new)document didn't finish the loading-process in your example, call document.close() after document.write()

http://jsfiddle.net/f2jFc/3/

Upvotes: 4

Related Questions