Open In App

HTML DOM Script async Property

The DOM Script async property is used to set or return 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:

Syntax: 



scriptObject.async
scriptObject.async = true|false

Property Values: It contains a Boolean value which specifies that whether the script should be executed asynchronously as soon as it is available, or not.

Return Value: It returns a Boolean value that specifies whether the script should be executed asynchronously or not.



Example: In this example, we will use the DOM Script async Property.




<!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() {
            let 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:


Article Tags :