Include JavaScript Code in HTML
suggest changeSyntax
<script type="text/javascript"> //some code </script><script type="text/javascript" src="URL"></script><script type="text/javascript" src="URL" async>//async code</script>
Parameters
Attribute | Details |
——— | —–– |src | Specifies the path to a JavaScript file. Either a relative or absolute URL. |type | Specifies the MIME type. This attribute is required in HTML4, but optional in HTML5. |async | Runs an external script asynchronously. It has no effect on an inline script. The attribute does not require a value (except in XHTML). | defer | Runs an external script after the document has been parsed, in document order. The attribute does not require a value (except in XHTML). | charset | Obsolete in HTML5. It specified the encoding of an external script. |crossorigin | How the element handles crossorigin requests |nonce | Cryptographic nonce used in Content Security Policy checks CSP3 |
Remarks
If the embedded JavaScript manipulates DOM elements, place the <script> element just before the closing </body> tag, or run it from a DOMContentLoaded listener (libraries such as jQuery can do that for you) so the DOM is ready.