1

I ma using twitter bootstrap tooltip functionality which works fine in gsp header texts. Now I want to add bootstrap tooltip on id="tooltipcheck". If I write title="{{data}}" then I could see the tooltip but bootstrap tooltip does not seem to work here. Is there any issue with js template or there is something else?

<script id="myTemplate" type="text/x-handlebars-template">
<div class="row">
    <div class="span4" id="tooltipcheck" data-placement="bottom" data-toggle="tooltip"  data-original-title="{{data}}">{{data}} </div>
</div>

I am calling tooltip like this.

      <script>

jQuery(function ($) {
    $("#tooltipcheck").tooltip('show');

});

2 Answers 2

1

You can't set the ID of an element in a template because ID's need to be unique. Try changing tooltipcheck to a class instead:

<div class="span4 tooltipcheck" data-placement="bottom" data-toggle="tooltip" data-original-title="{{data}}">{{data}} </div>

And then initialize your tooltips using the class:

$(".tooltipcheck").tooltip('show');

The tooltips will need to be initialized after handlebars has parsed the template and generated your markup, or else the tooltips won't have any elements to bind to.

3
  • You're sure that your tooltips are initializing after handlerbars has generated your markup?
    – cfs
    Aug 13, 2013 at 11:52
  • how can I check that? Aug 13, 2013 at 11:57
  • Not sure; I've never worked with handlebars before, but I'm guessing you have to call some javascript to get it to read the template and inject the generated HTML into the page. You should initialize your tooltips after that.
    – cfs
    Aug 13, 2013 at 12:05
0

since you are working with dynamic elements, after the elements are added to the dom you need to initialize the tooltip for the new elements

Ex:

var html = // html from template
var el = $(html).appendTo('somele');
el.find('<tooltip-element>').tooltip('show');

Also since you are using a template I'm assuming there will be multiple instances of the template in the page, so do not use id inside the template since in dom an id should be present only once

3
  • Sorry .. but I am new to this.. how should I get // html from template... & then should I append to existing div tag? Aug 13, 2013 at 11:51
  • @user1298426 please share the code where the template is used Aug 13, 2013 at 11:52
  • I am not sure how much it will be useful... but I shared some part related to js template and tooltip. jsfiddle.net/gaurav14u/whrUP/1 Aug 13, 2013 at 12:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.