HTML | DOM Script charset Property

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

  • Before Clicking on Button:
  • After Clicking on Button:

Example 2: This example illustrates how to set the script charset property.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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


My Personal Notes arrow_drop_up


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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.