Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:31:06+00:00 2026-05-31T20:31:06+00:00

I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in

  • 0

I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in fact, most of the code is copy-paste from it). This widget has a custom destroy method that hides the widget and removes it from the DOM. Again, it’s pretty much copy-paste from UI-dialog.

    destroy: function() {
        var self = this;

        if (self.overlay) {
            self.overlay.destroy();
        }
        self.close();
        self.element
            .removeData('popover');
        self.uiPopover.remove();
        console.log('afterRemove')

        return self;
    },

The weird thing is that this causes an infinite loop that throws some errors:

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

As far as I can see, the problem is that when I call .remove(), it automatically calls destroy() on my widget (this is built-in in jQuery UI) and the destroy methodd tries to call remove() again on my element, and then that tries to call destroy() again and so on..

However, the weird thing is that this doesn’t happen with UI dialog. So when I do this:

$('#element').dialog();
$('#element').remove();

Everything is okay… There must be something wrong with my plugin, but I cannot figure out what.

Here is the full source of my plugin: https://gist.github.com/2208569

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:31:07+00:00Added an answer on May 31, 2026 at 8:31 pm

    There’s not much you can do about the recursive call to destroy(), aside from modifying jQuery UI itself. You can, however, break the chain by preventing remove() from being called again:

    destroy: function() {
        var self = this;
    
        if (self.overlay) {
            self.overlay.destroy();
        }
        self.close();
    
        if (self.element.data("popover")) {
            self.element.removeData("popover");
            self.uiPopover.remove();
        }
    
        return self;
    }
    

    Note in passing that you don’t have to copy and paste code in order to augment existing widgets, as the widget framework supports prototype inheritance. It would be interesting to know if your problem still occurs if you have your widget derive from $.ui.dialog instead of duplicating its code base.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom jQuery widget that is being called from my app that
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a series of custom jQuery events for use in mobile web
Using jquery dialog I have created a popup box with a form. I am
I have created a custom jQuery UI theme. One of my styles .ui-state-hover takes
I have created a custom jQuery plugin that does some simple image resizing for
I have created a custom Jquery Timer. but i am facing little problem i
I have included jquery-1.7.2.min first and then jquery-ui-1.8.21.custom.min then I have dynamically created divs
I have created custom posts and I want one page in my site to
I have created custom cell in which there are n number of image views.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.