1

I am trying to add a tooltip that shows an image. This needs to be done via JS injection. I can use jQuery. For testing - I am using the same image for both the view, and when a user hovers over the image it should show the same image in the tooltip. Here is my current code that is not working:

<img src="https://images.quickbase.com/si/16/751-binary_view.png"  onload="$(this).tooltip({content: "<img src='https://images.quickbase.com/si/16/751-binary_view.png'/>"});">
3
  • Which tooltip library have you used? Commented Jun 15, 2017 at 14:59
  • Just use Qtip2 or any other tooltip plugin. Commented Jun 15, 2017 at 15:00
  • jQuery tooltip: jqueryui.com/tooltip Commented Jun 15, 2017 at 15:02

1 Answer 1

2

EDIT: I've added a data-tooltip to tag the images with tooltips (in contrast to those that don't).

You must escape the quotes (at least):

<img src="https://images.quickbase.com/si/16/751-binary_view.png"
  onload="$(this).tooltip({
    content: \"<img src='https://images.quickbase.com/si/16/751-binary_view.png'/>\"
  });"
/>

Maybe it's better to keep it outside the tag altogether.

<img src="https://images.quickbase.com/si/16/751-binary_view.png"
  data-tooltip="true" />

and somewhere in the header:

$(function () {
  $("img[data-tooltip='true']").each(function () {
    $(this).on("load", function () {
     var content;

     content = "<img src='{src}'/>".replace("{src}", $(this).attr("src"));
     $(this).tooltip({ "content": content });
    });
  });
});

The data-tooltip="true" attribute allows you to choose exactly which images should have a tooltip and which not (simply omit it in the latter case).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.