When trying to use the jQuery tooltip plugin, the object does not have a "tooltip" method

I use this tooltip: http://flowplayer.org/tools/demos/tooltip/index.html

My html file has the following lines:

<script src="/javascripts/home.js" type="text/javascript"></script> <script src="http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js" type="text/javascript"></script> <script type="text/javascript" src="/scripts/jquery.min.js"></script> <div id="boo"> <img src="image1.jpg" title="this thing is a tool"/> <img src="image2.jpg" title="this thing is also tool"/> </div> 

I have the following line in my home.js file:

 $("#boo img[title]").tooltip(); 

I have the following line in my css file:

 .tooltip { display:none; background:transparent url(/tools/img/tooltip/black_arrow.png); font-size:12px; height:70px; width:160px; padding:25px; color:#fff; } 

I get this error:

 Uncaught TypeError: Object [object Object] has no method 'tooltip' 

I'm crazy. I feel that I have definitely followed the example on the site, but I donโ€™t know what is happening.

+6
source share
3 answers

You should reorder your js files:

 <script type="text/javascript" src="/scripts/jquery.min.js"></script> <script src="http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js" type="text/javascript"></script> <script src="/javascripts/home.js" type="text/javascript"></script> 

A little more explanation for everyone who has this problem:

Scripts are loaded in the order in which they are called, so you want to load jQuery first, then any plugins, and then your own code.

+11
source

You also had a problem, and due to the old version of jquery lost in the sources folder there was jquery v1.6.2. If this can help someone ... Have a nice day!

+3
source

Wrap $("#boo img[title]").tooltip(); in $(function(){ }); so you finish:

 $(function(){ $("#boo img[title]").tooltip(); }); 

Why:

$(function()... is a short header for executing this code in the domReady event, so at this point all jquery files and the page will be loaded far enough for your javascript to work.

+1
source

Source: https://habr.com/ru/post/898333/


All Articles