HTML - DOM Document characterSet Property



HTML DOM document characterSet property is used to get character encoding of the document. It will return null if the document is created in memory.

Syntax

document.characterSet;

Return value

The characterSet property returns string representing character encoding of the document.

Example of HTML DOM Document 'characterSet' Property

The following example gives the character encoding of the document if you click the button.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML DOM document charset</title>
</head>
<body>
    <button onclick="fun()">Click Me</button>
    <p id="abc"></p>
    <script>
        function fun(){
        let enc = document.characterSet;
        document.getElementById("abc").innerHTML=
        "Encoding of the document is :" +enc;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
characterSet Yes 1 Yes 12 Yes 1 Yes 3 Yes 12.1
html_dom.htm
Advertisements