Does javascript have to be in the head tags?

后端 未结 11 697
逝去的感伤
逝去的感伤 2020-11-27 03:46

I believe javascript can be anywhere (almost), but I almost always see it in between . I am using jquery and wanted to know if it has

11条回答
  •  孤城傲影
    2020-11-27 04:13

    1. Because you don't want JavaScript mixed with HTML - content with behaviour. Preferably you want it in a separate file.

    2. Having JS elsewhere has advantages and disadventages - it will be executed at different time, for instance, and you can write to the document from javascript located in the body.

提交回复
热议问题