html tutorial - defer Attribute in HTML - html5 - html code - html form
Learn html - html tutorial - defer attribute in html- html examples - html programs
- The defer attribute is a Boolean attribute.
- The defer attribute specifies that the script is executed after the page has finished parsing.
Syntax for defer attribute in HTML:
Sample Coding for defer Attribute in HTML:
Sample Coding for defer attribute script.js:
Code Explanation for defer Attribute in HTML:
- defer attribute is used to specify the script file must be load after parsing the page content
- The alert box will be display the value of the element which has id as “p1”.
Output for defer Attribute in HTML:
- The content is written inside the <p> tag as it is shown in the output.
- alert dialog box shows “Wikitechy”. If we did not declare the defer attribute the value cannot be displayed in the alert box, because the script file declared before the content.
Browser Support for defer Attribute in HTML:
Tips and Notes
- The defer attribute is only used in external <script> element.