Skip to content Skip to sidebar Skip to footer

Add Tooltip In A Anchor Link

I want to add a tooltip in a text so for example if I have a code like this: Google! On mous

Solution 1:

If you wish to create it dynamically using jquery, you may do the following :

<ahref="http://google.com"data-title="The World's Largest Search Engine!">Google!</a><style>.box
{
  border: 1px solid green;
  position:absolute;
  color: white;
  top: 19px;
  left: 30px;
  background-color: black;
}
</style><script>
$().ready(function(){
$( "a" ).hover(
  function() {   
   var title = $(this).attr("data-title");  // extracts the title using the data-title attr applied to the 'a' tag
    $('<div/>', { // creates a dynamic div element on the flytext: title,
        class: 'box'
    }).appendTo(this);  // append to 'a' element
  }, function() {
    $(document).find("div.box").remove(); // on hover out, finds the dynamic element and removes it.
  }
);
  });
</script>

Example : http://jsfiddle.net/9RxLM/5164/

Post a Comment for "Add Tooltip In A Anchor Link"