Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

position of JavaScript in HTML page

Options
  • 14-07-2004 3:16pm
    #1
    Registered Users Posts: 629 ✭✭✭


    It seems to me that sometimes JavaScript can be placed anywhere in the HTML page, but sometimes it has to be in the <head> tag.

    Do anyone know the answer or any information on this?


Comments

  • Closed Accounts Posts: 44 Err..


    I think the only reasons for putting JS code in the head section are:

    1. It makes for more readable code.
    2. It prevents your JS functions being called before they're loaded.


  • Closed Accounts Posts: 2,313 ✭✭✭Paladin


    Scripts in the body section will be executed WHILE the page loads.

    Scripts in the head section will be executed when CALLED.

    See ww3 schools:

    http://www.w3schools.com/js/js_whereto.asp


  • Registered Users Posts: 629 ✭✭✭str8_away


    Thanks guys :)


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    Originally posted by Paladin
    Scripts in the body section will be executed WHILE the page loads.

    Scripts in the head section will be executed when CALLED.

    While that is true, the opposite is also true.

    .cg


Advertisement