Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add tooltip in a anchor link [duplicate]

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

<a href="http://google.com" title="The World's Largest Search Engine!">Google!</a>

On mouse hover, I want to show that tooltip. Using title is a good way but how can I style to look it better? Any help: JSFIDDLE

like image 587
Estina Esitna Avatar asked Sep 25 '22 23:09

Estina Esitna


1 Answers

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

<a href="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 fly
        text: 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/

like image 80
DinoMyte Avatar answered Oct 20 '22 07:10

DinoMyte