Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML DOMException code property

Improve Article
Save Article
  • Last Updated : 06 Jul, 2022
Improve Article
Save Article

The code property of the DOMException interface returns a short number that contains the error code of the exception error, or 0 if none match. This is a read-only property.


var codeNumber = domException.code;

Note: This property has been DEPRECATED and is no longer recommended.

Return Value: This property returns a short number.

Example: In this example, we will create an INVALID_CHARACTER_ERR and then show its code.


<!DOCTYPE html>
  <meta charset="utf-8">
  <title>DOMException code example</title>
  <p>Click below to get the exception code</p>
  <button onclick="get()">Click</button>
  <p class="p">Error Code is : </p>
    function get(){
        try {
                // INVALID_CHARACTER_ERR
            var elem = document.createAttribute ("123");
        catch (e) {
            console.log("Error is :", e);
            console.log("Errorcode is :", e.code);


Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!