Investigate the relationship between the storage and function of JavaScript tags.
On a webpage, we can place JavaScript code anywhere in an html file, but generally in a head or body tag.
In general, where <script> elements are placed is closely related to their functions. Here we will discuss two situations:
1. Put it in
The <script> element is placed in the head to allow the browser to read from the beginning. The <script> element is loaded and executed at the beginning of the parsing of the entire webpage, its priority is second only to <title> elements.
Then parse the rendering in sequence.
Application: for example, JavaScript code for page display initialization must be placed in the head.
2. In the <body> section
The browser parses the Code in order of page tags. When the JavaScript code is read, the statement is executed.
However, some JS functions are called through events, so the specific location on the page does not affect the time when the function is applied. Therefore, considering the front-end performance problems, you can put the JS Code that is not the first execution and event call at the bottom of the body.
Write and read:
<! Doctype html>
As you can see above, the storage and function of javascript labels are closely related. I hope this article will help you.
Articles you may be interested in:
- Location of javascript labels on the page
- Sample Code for JS Implementation of switching the tab Effect
- Js: click "a" to highlight the color of the current tag.
- Js listens to the scroll bar event so that the content of a label is always in the same position.
- A simple tab with style written in pure css + js
- Use JS or jQuery to simulate Mouse clicking a tag Event code
- Js implementation of a label hyperlink to submit form Method