Javascript Reference - HTML DOM DFN Object








The DFN object represents an HTML <dfn> element.

Standard Properties and Events

The DFN object also supports the standard properties and events.

Example

The following code shows how to get a <dfn> element by using getElementById()


<!DOCTYPE html>
<html>
<body>
<dfn id="myDFN">Definition term</dfn>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--   w  w  w  . ja  va2s  . c o  m-->
    var x = document.getElementById("myDFN");
    x.style.color = "red";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to create a <dfn> element by using the document.createElement() method


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button><br><br>
<script>
function myFunction() {<!--   ww w  . jav a2  s.co m-->
    var x = document.createElement("DFN");
    var t = document.createTextNode("A definition term");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>
</body>
</html>

The code above is rendered as follows: