Javascript Reference - HTML DOM Abbreviation Object








The Abbreviation object represents an HTML <abbr> element.

Example

The following code declares an abbr element. The Javascript code uses the getElementById to get it and outputs its title value.


<!DOCTYPE html>
<html>
<body>
<p><abbr id="myAbbr" title="HTML tutorial">html</abbr></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w w  w.  j  a va 2s . c o m-->
    var x = document.getElementById("myAbbr").title;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code creates an <abbr> element by using the document.createElement() method:


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="myP"></p>
<script>
function myFunction() {<!--   ww  w  .j  a v a2 s.  co  m-->
    var x = document.createElement("ABBR");
    var t = document.createTextNode("HTML");
    x.setAttribute("title", "html tutorial");
    x.appendChild(t);
    document.getElementById("myP").appendChild(x);
}
</script>
</body>
</html>

The code above is rendered as follows:





Standard Properties and Events

The Abbreviation object supports the standard properties and events.