HTML script tag

HTML <script> tag adds the script in the html document. Script can be added directly in between the elements (inline) or imported from an external source using src attribute.

<p>script element is used to add javascript in a page. For example, we make a function of cube in javascript.</p>	
<script>
 var x=5;
 function product(x){
 document.write(x*x*x);
 }
 product(5);
</script>
</>

script element is used to add javascript in a page. For example, we make a function of cube in javascript.

Tag Uses

Specific uses of <script> tag

It makes the content dynamic.

Tag omission

Both opening and closing tags are necessary for the script element.

Global Attributes

All the global attributes are applicable on the script element.

Tag Attributes

Attributes that are applicable to <script> tag
src

Address of the file to be imported.

<script src="address of the file to be improted"> </script>
type

Specifies the type of language of the script.

<script src="address" type="text/javascript"> ...... </script>
crossorigin

describes about the crossorigin requests.

<script crossorigin="anonymous"> ..... </script>
charset

describes about the crossorigin requests.

<script charaset="UTF-8"> ..... </script>

Tip: The script should be placed at the end of a page.



Was this article helpful?