HTML | DOM Script async Property
The DOM Script async property is used to set or returns whether a script should be executed asynchronously or not. This property is used to reflect the async attribute. This attribute only works for the external script.
There are the following ways that the external script could be executed:
- The script will be executed asynchronously with the rest of the page when async is present. Means while the page continues the parsing that time script will be executed.
- If the defer is present but async is not present then the script will be executed when the page has finished parsing.
- If both, async or defer is not present then the script is fetched and will execute immediately, even before the browser continues parsing the page.
Syntax:
- It return the async property.
scriptObject.async
- It is used to Set the async property.
scriptObject.async = true|false
Property Values: It contains a Boolean value which specify that whether the script should be executed asynchronously as soon as it is available, or not.
- True: It specifies that the script should be executed asynchronously.
- false: It specifies that the script will not be executed asynchronously.
- Before Clicking on Button:

- After Clicking on Button:

- Google Chrome
- Internet Explorer 10.0
- Firefox
- Safari
- Opera
- HTML | <script> async Attribute
- HTML | DOM Script src Property
- HTML | DOM Script defer Property
- HTML | DOM Script text Property
- HTML | DOM Script type Property
- HTML | DOM Script charset Property
- HTML | async Attribute
- HTML | script Tag
- HTML | <script> src Attribute
- HTML | DOM Script Object
- HTML | <script> charset Attribute
- HTML | <script> type Attribute
- HTML | <script> defer Attribute
- Async/Await Function in JavaScript
- HTML | DOM li value Property
Return Value: It returns a Boolean value which specifies that the script should be executed asynchronously or not.
Example:
<!DOCTYPE html> <html> <head> <title> HTML DOM Script async Property </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h2>DOM Script async Property </h2> <p id="p1">Hello World!</p> <script id="myScript" src="demo_async.js" async></script> <!-- Button that trigger the Function --> <button onclick="myFunction()">Click me!</button> <p id="demo"></p> <!-- Main Function --> <script> function myFunction() { var x = document.getElementById("myScript").async; document.getElementById("demo").innerHTML = x; } </script> </body> </html> |
Output:
Supported Browsers: The browser supported by HTML DOM Script async property are listed below:
Recommended Posts:
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.



