The HTML DOM Script charset property is used to set or return the value of a charset attribute of an <script> element. The charset attribute is used to specifies the character encoding used in an external script.
Syntax:
- It returns the charset property.
scriptObject.charset
- It is used to set the charset Property.
scriptObject.charset = charset
Property Values: It contains single value charset which specifies the character encoding used in an external script.
- “ISO-8859-1”: It is used to specify the standard encoding for the Latin alphabet.
- “UTF-8”: It is used to specify the character encoding for Unicode. Compatible with ASCII.
Return Value: It returns a string value which represents the character encoding of the script element.
Example: This example illustrates how to return the script charset property.
<!DOCTYPE html> <html> <head> <title> DOM script charset Property </title> </head> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> DOM script charset property </h3> <script id="myGeeks" type="text/javascript" src="my_script.js" charset="UTF-8"> </script> <br> <button onclick="Geeks()">Submit</button> <h2 id="demo"></h2> <script> function Geeks() { var x = document.getElementById("myGeeks").charset; document.getElementById("demo").innerHTML = x; } </script> </center> </body> </html> |
Output:
- Before Clicking on Button:

- After Clicking on Button:

Example 2: This example illustrates how to set the script charset property.
<!DOCTYPE html> <html> <head> <title> DOM script charset Property </title> </head> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> DOM script charset property </h3> <script id="myGeeks" type="text/javascript" src="my_script.js" charset="UTF-8"> </script> <br> <button onclick="Geeks()">Submit</button> <p id="demo"></p> <script> function Geeks() { var x = document.getElementById("myGeeks").charset = "ISO-8859-1"; document.getElementById("demo").innerHTML = "The value of the charset Attrinbute" + " was changed to: " + x; } </script> </center> </body> </html> |
Output:
- Before Clicking on Button:

- Aftre Clicking on Button:

Supported Browsers: The browsers supported by HTML DOM Script charset property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- HTML | <script> charset Attribute
- HTML | DOM Script src Property
- HTML | DOM Script text Property
- HTML | DOM Script type Property
- HTML | DOM Script async Property
- HTML | DOM Script defer Property
- ASP Charset Property
- HTML | <a> charset Attribute
- HTML | charset Attribute
- HTML | accept-charset Attribute
- HTML | <link> charset Attribute
- HTML | <meta> charset Attribute
- HTML | <form> accept-charset Attribute
- HTML | script Tag
- HTML | <script> src Attribute
- HTML | DOM Script Object
- HTML | <script> type Attribute
- HTML | <script> async Attribute
- HTML | <script> defer Attribute
- CSS | @charset Rule
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


