Achal Gupta
Achal Gupta

Reputation: 454

Error: No method named "destroy" for popover bootstrap

I want to close popover automatically after a delay time. but its showing an error error image

$('#prev_button').popover('show');

$('#prev_button').on('shown.bs.popover', function() {
  var $pop = $(this);

  setTimeout(function() {
    $pop.popover('destroy');
  }, 1000);
});

bootstrap.bundle.js is included to ensure popover method works. Can't figure out a solution

PS: using v4.1 bootstrap

Upvotes: 10

Views: 11234

Answers (3)

31piy
31piy

Reputation: 23859

As of version 4.1, the method destroy has been replaced by dispose. You can find more details here.

$pop.popover('dispose');

Upvotes: 27

The Popover plugin is similar to tooltips. To destroy the shown popover you can use the following code-snippet:

$pop.popover('destroy'); // jQuery < 4.1
$pop.popover('dispose'); // jQuery > 4.1

You can also remove all created popovers from your DOM via .popover class (each popover has an id, so by knowing the IDs you can be more precise)

$('.popover').remove();

Upvotes: 0

Aditya Sharma
Aditya Sharma

Reputation: 663

Please share bootstrap version details for better help & it would be better if you could prepare a jsfiddle.
Here is a jsfiddle link where you can find your code working with Bootstrap 3.0.
If you are using Bootstrap 4 following reference would help.
Some suggestions:
1. If you just intend to close it you should use hide rather than destroy.
2. You can also directly pass delay as an option to delay show or hide such that

delay: { 
   show: "500", 
   hide: "1000"
},

HTH

Upvotes: 1

Related Questions