Javascript Reference - HTML DOM Script async Property








The async property sets or gets whether a script should be executed asynchronously.

This property maps to the async attribute of the <script> tag.

Browser Support

async Yes 10.0 Yes Yes Yes

Syntax

Return the async property.

var v = scriptObject.async 

Set the async property.

scriptObject.async=true|false




Property Values

Value Description
true|false Specifies whether a script should be executed asynchronously.
  • true - The script will be executed asynchronously
  • false - The script will not be executed asynchronously

Return Value

A Boolean type value, returns true if the script is executed asynchronously, otherwise it returns false.

Example

The following code shows how to check if a script was executed asynchronously.


<!DOCTYPE html>
<html>
<body>
<script id="myScript" src="demo_async.js" async></script>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--   w  w w.  jav  a  2s.c o m-->
<script>
function myFunction() {
    var x = document.getElementById("myScript").async;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: