HTML DOM title Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM title property returns/sets a string corresponding to the value of the title attribute of a HTML element. The title value shows up when hovering over HTML element.

Following is the syntax −

Returning string value

ElementOfHTMLObject.title

Set title to a string value

ElementOfHTMLObject.title = string

Example

Let us see an example of HTML DOM title property −

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM title</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-title</legend>
         <input type="text" id="textSelect" title="" >
         <input type="button" onclick="getTitle()" value="Better define the above field">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var textSelect = document.getElementById("textSelect");
   function getTitle() {
      if(textSelect.title === ''){
         divDisplay.textContent = 'Details defined now! Please hover over field';
         textSelect.title = 'Full Name Expected';
      }
   }
</script>
</body>
</html>

Output

Before clicking ‘Better define the above field’ button −

After clicking ‘Better define the above field’ button −

raja
Published on 29-Oct-2019 09:47:26
Advertisements