2

How do i get the this property of the popover for twitter bootstrap parameter values, like i need to get the list item attribute i.e. data-boothtype to be used in bootstrap popover title? data-title is not enough though

HTML

<li class="booth" data-boothnumber="46" data-boothtype="prime" style="left: 240px; top: 30px;">46</li>

JS

$('.booth').popover({title: this.data-boothtype + "'s Booth", content: "test", placement: "right", callback:function(){ console.log(this)}});

PS: The callback function is a test unit from Callback function after tooltip / popover is created with twitter bootstrap?

$.fn.popover.Constructor.prototype.show = function () {
  tmp.call(this);
  if (this.options.callback) {
    this.options.callback();
  }
}

EDIT ok here narrowed down: http://jsfiddle.net/tHHQ6/

Community
  • 1
  • 1
user1076813
  • 487
  • 6
  • 18
  • `this.data-boothtype` wouldn't even be valid JavaScript code. It's important to get the very basics first... – elclanrs Mar 27 '13 at 02:58
  • oh yeah, thanks for that anyways, just the idea of calling the object's propert(ies)... and maybe i missed a much of the basics aside from that... – user1076813 Mar 27 '13 at 09:50

2 Answers2

3

You need to do

$('.booth').each(function(i, v){
    var $el = $(v);
    $el.popover({
        title: 'test' + $el.data('boothnumber'), 
        content: "test", 
        placement: "right"
    });
});

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • i'd never thought that calling a dom recursively and each given a property w/c is accessible directly is a good idea, thanks for this anyways, here have an upvote :) – user1076813 Mar 27 '13 at 09:53
  • in this case that is the only way since the title has to be found out dynamically – Arun P Johny Mar 27 '13 at 09:56
0

Using JQuery you could do something like:

$('.booth').data('boothnumber')

See here for the .data() api

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
Daniel Powell
  • 8,143
  • 11
  • 61
  • 108
  • the question might be misleading though, sorry for that and thanks anyway. I just wanted the current($this) data to be used in the bootstrap popover title... here let me help you help me :) http://jsfiddle.net/tHHQ6/ – user1076813 Mar 27 '13 at 03:11