- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM DFN object
The HTML DOM DFN object is associated with the HTML <dfn> element. The text inside the <dfn> element is the one being defined in the surrounding context. The DFN object represents the <dfn> element.
Syntax
Following is the syntax for −
Creating a DFN object −
var p = document.createElement("DFN");
Example
Let us look at an example for the HTML DOM DFN object −
<!DOCTYPE html> <html> <body> <h2>DFN object example</h2> <p>Click the below button to create a dfn element with some text inside it.</p> <button onclick="dfnCreate()">CREATE</button> <br><br> <script> function dfnCreate() { var x = document.createElement("DFN"); var t = document.createTextNode("The defination element"); x.appendChild(t); document.body.appendChild(x); } </script> </body> </html>
Output
This will produce the following output −
On clicking the CREATE button −
We have first created a button CREATE that will execute the dfnCreate() function when clicked by the user −
<button onclick="dfnCreate()">CREATE</button>
The dfnCreate() method creates a <dfn> element using the createElement() method of the document object. It then creates a text node using the createTextNode() method. The text node is then appended as a child to the <dfn> element. Finally the <dfn> element along with the text node are appended as the child of the document body using the appendChild() method −
function dfnCreate() { var x = document.createElement("DFN"); var t = document.createTextNode("The definition element"); x.appendChild(t); document.body.appendChild(x); }