HTML | DOM Script defer Property


The Script defer Property is used to set or return whether the script should be executed after the page has finished parsing. This Property is used to reflect the defer attribute of a <script> Tag.
This attribute is only used for External JavaScript File.

Syntax

  • It Return the defer property.
    scriptObject.defer
  • It is used to set the defer property
    scriptObject.defer = true|false

Property Values: It contains the Boolean value which specify that whether a script should be executed when the page has finished parsing, or not



  • true : The script is executed when the page has finished parsing
  • false: The script will not be executed when the page has finished parsing.

Return Values: It returns a boolean value, returns true if the script is executed after the loading of the page is finished.

Example: This Example returns the defer Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head
    <title
        DOM script src Property 
    </title
</head
  
<body style="text-align:center;"
    <h1
        GeeksForGeeks 
    </h1
      
    <h2
        DOM script defer property
    </h2
      
    <script id="myGeeks" type="text/javascript" src="my_script.js" defer>
    </script><br>
    <button onclick="Geeks()">Submit</button>
    <h2 id="demo"></h2>
     <script>
                 function Geeks()  {
          var x = document.getElementById("myGeeks").defer;
  document.getElementById("demo").innerHTML =  x;
}
                 
     </script>
       
</body
  
</html>                         

chevron_right


Output:

Before Clicking On Button :

After Clicking On Button :



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.