How to add tooltip to textbox in Javascript?




Hi All,

In this article, I'll be talking about adding tooltip in Javascript
Adding a tooltip to a textbox in Javascript is easy. You just have to set the attribute title for the HTML input tag.

setAttribute() method can be used to set title for the input.

Example :
 <html>  
  <body>  
   <input type="text" id="inp"/>  
   <script>  
       var el = document.getElementById("inp"); //getting input tag by id inp
       el.setAttribute("title","tooltip_text_you_want_to_set"); //setting attribute title
   </script>  
  </body>  
 </html>  


But I would suggest adding tooltip directly in the HTML input tag using title attribute.

 <input type="text" id="inp" title="tooltip_text_you_want_to_set" />