HTML | DOM DFN Object

The DOM DFN Object is used to represent the HTML <dfn> tag. The DFN element is accessed by getElementById().

Syntax:

document.getElementById("ID");

Where “id” is the ID assigned to the “dfn” tag.



Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM DFN Object</title>
</head>
  
<body>
    <H2>DOM DFN Object</H2>
    <p>
       <!-- Id assigned to the dfn tag. -->
       <dfn id="GFG">Geeksforgeeks
      </dfn> is a portal for geeks.
    </p>
    <button onclick="myGeeks()">Submit</button>
    <script>
        function myGeeks() {
            <!-- accessing dfn -->
            var gfg = document.getElementById("GFG");
            gfg.style.color = "coral";
            gfg.style.fontSize = "20px";
        }
    </script>
</body>
  
</html>           

chevron_right


Output:

Before Clicking On Button :

After Clicking On Button:

Example-2: DFN Object can be created by using the document.createElement Method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM DFN Object</title>
</head>
  
<body>
    <H2 style="font-size:35px;">
      DOM DFN Object
    </H2>
    
    <p>It is a portal for geeks.</p>
    <button onclick="myGeeks()">
      Submit
    </button>
  
    <script>
        function myGeeks() {
            var gfg = document.createElement("DFN");
            var f = document.createTextNode("GeeksForGeeks");
            gfg.appendChild(f);
            document.body.appendChild(gfg);
        }
    </script>
</body>
  
</html>

chevron_right


Output :

Before Clicking On Button :

After Clicking on Button:

Supported Browsers: The browser supported by DOM DFN Object are listed below.

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.