The title property sets or gets the value of the title attribute of an element.
Ge the title of an <abbr> element:
var x = document.getElementById("myAbbr").title;
Click the button to display the title of the abbr element below.
<!DOCTYPE html> <html> <body> <p><abbr id="myAbbr" title="World Health Organization">WHO</abbr> was founded in 1948.</p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// ww w . j av a 2 s. c om var x = document.getElementById("myAbbr").title; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The title attribute specifies extra information about an element.
The information is often shown as a tooltip text when the mouse moves over the element.
Property Values
Value | Description |
---|---|
text | A tooltip text for an element |
The title property returns a String, representing the title of the element.