Create an Abbreviation Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Abbreviation

Introduction

You can create an <abbr> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="myP"></p>

<script>
function myFunction() {/* w w w .  j  a  v  a  2s .c  o  m*/
    var x = document.createElement("ABBR");
    var t = document.createTextNode("abbr text");
    x.setAttribute("title", "title of abbr");
    x.appendChild(t);
    document.getElementById("myP").appendChild(x);
}
</script>

</body>
</html>

Related Tutorials