Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

script placing

 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish to know what's the different if script in head and in body. Is there any difference on when and how the script is executed?


gave me original with error : p1 is null. can anybody explain why ? thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, look at the file. Does p1 exist when the script is encountered?

Some people will put the script at the end of the file, after the DOM has been constructed, and there are claims that this is more performant than other locations. (I have yet to see much of any difference.)

But most people will put initialization code in one of a load event handler, or a ready handler (if using jQuery).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic