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: In this example, we will use DOM DFN Object.
html
<!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" >w3wiki </ dfn > is a portal for Beginner. </ p > < button onclick = "myBeginner()" >Submit</ button > < script > function myBeginner() { // accessing dfn let gfg = document.getElementById("GFG"); gfg.style.color = "coral"; gfg.style.fontSize = "20px"; } </ script > </ body > </ html > |
Output:
Example 2: DFN Object can be created by using the document.createElement Method.
HTML
<!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 Beginner.</ p > < button onclick = "myBeginner()" > Submit </ button > < script > function myBeginner() { let gfg = document.createElement("DFN"); let f = document.createTextNode("w3wiki"); gfg.appendChild(f); document.body.appendChild(gfg); } </ script > </ body > </ html > |
Output :
Supported Browsers: The browser supported by DOM DFN Object are listed below.
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari