简体   繁体   中英

Bootstrap tooltips and popovers: To Destroy, or NOT To Destroy?

if I create tooltips and popovers via BS' tooltip() and popover() methods, is there a need to do any explicit destroying of said creations if the DOM changes and the affected elements are no longer present? Am I creating JS dust bunnies by NOT explicitly destroying?

to put toolips on dynamic content you should use a delegate as such: $('body').toolip({selector: '.has-tooltip'}); and in this case, destroying is not needed.

https://github.com/twbs/bootstrap/issues/4215

http://jsbin.com/zopod/1/edit?html,css,js,output

I created a simple fiddle:

http://jsfiddle.net/Oski/5gura2oq/

JS:

$(function () {
  var element = $('#example').popover();
  element.popover('show');
  element.remove();
});

Template:

<p>Click on button to see Popover</p>
<a href="#" id="example" class="btn btn-primary" rel="popover"
  data-content="This is the body of Popover"
  data-original-title="Creativity Tuts">pop
</a>

You can remove the anchor element and still have the popover visible, so I think you need to destroy your popover.


Hello,


No need to destroy, when you close the popover or the tooltip automatically it is excluded from the DOM.


Here is an tooltip example:

image description here


In this example I use jquery ui tooltip.


I hope I have helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM