3

How to use jQuery UI Tooltips to dynamically show Div containers based on a given attribute, other than title attribute ?

Fiddle Sample will show my problem :

Example Fiddle

I have different links, which can have a title attribute as well, and if there is a given attribute, Tooltip should read the value and show the contributing Div.

Sample:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="toolTipHTML" data-ttcontent="help1_content" title="test 1">Help 1</span>
<span class="toolTipHTML" data-ttcontent="help2_content" title="test 2">Help 2</span>

<div class="help1_content">
  Text for Help 1 goes here!
  <br>Lorem
  <br>Ipsum
</div>

<div class="help2_content">
  Text for Help 1 goes here!
  <br>Lorem
  <br>Ipsum
</div>

Currently it only shows the title attributes, which is the standard behavior. But I want to change the call this way, that I can see the Divs in a tooltip (the Divs only contain Text in this sample, but can be by far more complex in reality).

2
  • 1
    check jqueryui.com/tooltip/#custom-content Commented Dec 8, 2016 at 10:48
  • Thx, I saw this, but was not able to build a working solution with the given information :-/ Commented Dec 8, 2016 at 11:19

1 Answer 1

3

Updated fiddle.

You could use content option for this purpose :

$('.toolTipHTML').tooltip({
  show: { duration: 0 },
  hide: { effect: "fade", duration: 100 },
  position: { my: "left top", at: "left bottom" },
  content: function() {
    return $('.'+$( this ).attr('data_ttcontent')+'_content').html();
  }
});

Hope this help.

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.