Friday, July 5, 2024
HomeLanguagesJavascriptHTML DOMException code property

HTML DOMException code property

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.

Syntax:

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.

html




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


Output:

Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Ted Musemwa
As a software developer I’m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments