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 >
< dfn id = "GFG" >Geeksforgeeks
</ dfn > is a portal for geeks.
</ p >
< button onclick = "myGeeks()" >Submit</ button >
< script >
function myGeeks() {
// 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 geeks.</ p >
< button onclick = "myGeeks()" >
Submit
</ button >
< script >
function myGeeks() {
let gfg = document.createElement("DFN");
let f = document.createTextNode("GeeksForGeeks");
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