javascript - how to get bootstrap popovers to work with dynamically generated image links? - Stack Overflow

I'm trying to get the Bootstrap 2 "popovers" to:A) work with dynamically generated conte

I'm trying to get the Bootstrap 2 "popovers" to:

A) work with dynamically generated content and
B) display an image inside of the popover.

My current code:

var image = '<img src="img/header/'+selection+'" />';
var previewLink = '<a class="headerPreview" href="#" rel="popover" >(Hover to Preview)    </a>';
$('#headerBlock').append(previewLink);
$('.headerPreview').popover({
    title: 'test',
    content: image
});

Right now, it does nothing when the link is hovered over. I'm not sure what I'm doing wrong.

I'm trying to get the Bootstrap 2 "popovers" to:

A) work with dynamically generated content and
B) display an image inside of the popover.

My current code:

var image = '<img src="img/header/'+selection+'" />';
var previewLink = '<a class="headerPreview" href="#" rel="popover" >(Hover to Preview)    </a>';
$('#headerBlock').append(previewLink);
$('.headerPreview').popover({
    title: 'test',
    content: image
});

Right now, it does nothing when the link is hovered over. I'm not sure what I'm doing wrong.

Share Improve this question edited Oct 21, 2012 at 9:34 Florent 12.4k10 gold badges50 silver badges58 bronze badges asked Oct 19, 2012 at 20:39 tdctdc 5,46412 gold badges59 silver badges107 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Try this: http://jsfiddle/KAvAZ/

The key is adding trigger: 'hover' to your popover object.

Each time you dynamically add some new content, if you want to make it popover-enabled (assume that your already add proper html tags), popover() function should be called right after you add the new content. This is what I do to enable popover on both original content and dynamically generated content.

This thread may help: Twitter Bootstrap Popovers not working for Dynamically Generated Content

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745508159a4630646.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信