Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you add an image to a jquery tooltip

Tags:

jquery

tooltip

I haven't seen this exact question addressed...if it has been, just please point me to it.

I'm using jquery's ui tooltip. I have one link that when you mouseover it, I'd like to show an image. Nothing has worked for me so far.

ui code in header:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>

HTML:

(see <a id='riverroad' href='#' title='' >image of 1 Maple St.</a>)

code:

$( "#riverroad" ).tooltip({ content: "<img src='./images/myimage.jpg/>" });

Please tell me what I'm doing wrong.

like image 234
LauraNMS Avatar asked Mar 07 '13 14:03

LauraNMS


People also ask

How do I add a tag in tooltip?

Via data attributes − To add a tooltip, add data-toggle = "tooltip" to an anchor tag. The title of the anchor will be the text of a tooltip. By default, tooltip is set to top by the plugin.

What is tooltip function in jQuery?

The jQuery UI tooltip() method adds tooltip to any element on which you want to display tooltip. It gives a fade animation by default to show and hide the tooltip, compared to just toggling the visibility. Syntax: You can use the tooltip() method in two forms. $(selector, context).tooltip (options) Method.

What is tooltip plugin?

The Tooltip plugin is small pop-up box that appears when the user moves the mouse pointer over an element: Hover over me Hover over me. Tip: Plugins can be included individually (using Bootstrap's individual "tooltip. js" file), or all at once (using "bootstrap. js" or "bootstrap.


1 Answers

try this one :

Html

<a id="riverroad" href="#" title="" >image of 1 Maple St.</a>

JQuery

$( "#riverroad" ).tooltip({ content: '<img src="yourImagePath" />' });

See the working fiddle.

Jquery 1.9.1 and JqueryUI 1.9.2 are included of course. Check if your image path is correct by the way.

Edit : You told me that you're setting the link with jQuery, see this second working example :

Html

<div id="content">    
</div>

JQuery

$(document).ready(function() {
   $("#content").html('<a id="riverroad" href="#" title="" >image of 1 Maple St.</a>');
   $("#content #riverroad").tooltip({ content: '<img src="http://icdn.pro/images/fr/a/v/avatar-barbe-brun-homme-utilisateur-icone-9665-128.png" />' }); 

});

Here is the new fiddle !

like image 174
soyuka Avatar answered Sep 22 '22 22:09

soyuka