Search code examples
jquerytooltiptooltipster

Jquery Tooltipster function to show the content when user hovers over it


I m a beginner at Tooltipster functions Below is my code:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>attr demo</title>
  <style>

  div {
    color: red;
    font-size: 24px;
  }

  </style>
  <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
  <script type="text/javascript" src="js/jquery.tooltipster.min.js"></script>
   <script>
        $(document).ready(function() {
            $('.tooltip').tooltipster();
        });
    </script>
</head>
<body>

<div id="my-tooltip"> 
        This div has a tooltip with HTML when you hover over it!
</div>
    <script>

        $(document).ready(function() {
            $( ".my-tooltip" ).tooltip({ content: "Awesome title!" });
            alert("dsad");
        });
    </script>
</body>
</html>

But the output is shows only this:

This div has a tooltip with HTML when you hover over it!

Also in console, there is error at line 30:$( ".my-tooltip" ).tooltip({ content: "Awesome title!" }); Uncaught TypeError: undefined is not a function

Help please!!! how to use tooltipster functions and use them..?


Solution

  • Check this Demo Fiddle

    $(document).ready(function() {
            $('#my-tooltip').tooltipster({
                content: $('<strong class="tooltip">Awesome title!</strong>')
            });
    });
    

    Just as an alternative, Jquery UI also supports .tooltip(). Its easy to use. In that case,

    $( ".selector" ).tooltip({ content: "Awesome title!" }); 
    

    will work, but you have to include jQuery UI.