Adding different Twitter Bootstrap popovers to dynamically created elements

时光毁灭记忆、已成空白 提交于 2019-12-23 07:45:43

问题


I'm trying to add popovers to dynamically created elements. Each kind of element (either a ContentEditable or an Img or a Video) needs to have a different popover content.

Because they are dynamic elements, I'm calling the popovers as follows:

$('body').popover({
            selector: '[rel=popoverImage]',
            content: **popoverImage**,
            html: true,
            placement: 'top',
            trigger: 'focus'
        });

Where popoverImage is a variable that has the content of the popover for the img element.

The issue comes when I try to add another popover. It doesn't show. I've tried the following:

  1. Having 2 Selectors and calling them in different $('body')popover({...}) functions.
  2. Changing the body element to a dynamically generated container.
  3. Changing the variable that has the "content" data each time a new element is focused.

Any ideas?


回答1:


What you need is when you add a new control add the popover at the same time:

function AddNewElement()
{
  var yourElement = '<div id="yourElementId"> The element you want </div>';
  $('divToAppend').append(youElement);

  var yourPopoverContent = 'Your Personalized popover';

  $('#yourElementId').popover({
      html : true,
      content : yourPopoverContent      
  });

}

This should work with your actual code for the popover.



来源:https://stackoverflow.com/questions/18731094/adding-different-twitter-bootstrap-popovers-to-dynamically-created-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!