Document.title() use in JavaScript?



The title property sets or returns the value of the title attribute of an element, nothing but providing extra information regarding the element. This is mostly used as a tooltip, which displays the text on mouse hovering. Javascript has provided document.title() to get the title.

syntax

document.title();

Example

In the following example, an abbr attribute is used inside a 'p' tag and the respective title abbreviation is found out using the method document.title(). Later on, the result is displayed in the output.

<html>
<body>
<p><abbr id="Abbr" title="Abraham lincoln"></abbr>A-l is one of the best presidents of America </p>
<p id="title"></p>
<script>
   var x = document.getElementById("Abbr").title;
   document.getElementById("title").innerHTML = x;
</script>
</body>
</html>

Output

A-l is one of the best presidents of America

Abraham lincoln
raja
Published on 16-Aug-2019 13:43:17
Advertisements