HTML Include JavaScript Code in HTML

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • <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

AttributeDetails
srcSpecifies the path to a JavaScript file. Either a relative or absolute URL.
typeSpecifies the MIME type. This attribute is required in HTML4, but optional in HTML5.
asyncSpecifies that the script shall be executed asynchronously (only for external scripts). This attribute does not require any value (except of XHTML).
deferSpecifies that the script shall be executed when the page has finished parsing (only for external scripts). This attribute does not require any value (except of XHTML).
charsetSpecifies the character encoding used in an external script file, e.g. UTF-8
crossoriginHow the element handles crossorigin requests
nonceCryptographic nonce used in Content Security Policy checks CSP3

Remarks

If the embed JavaScript code (file) is used to manipulate http://stackoverflow.com/documentation/javascript/503/document-object-model-dom Elements, place your <script></script> tags right before the closing </body> tag or use JavaScript methods or libraries (such as jQuery to handle a variety of browsers) that makes sure the DOM is read and ready to be manipulated.



Got any HTML Question?