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

  • SEARCH
  • Home
  • 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 8125465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:49:38+00:00 2026-06-06T06:49:38+00:00

I am using the jquery plugin boilerplate ( available here ) to create an

  • 0

I am using the jquery plugin boilerplate (available here) to create an extension of the div element. The plugin is meant to add other divs or elements inside the original div. My problem is that I would like to be able to destroy and re-create the elements inside the div.

Here is a simplified example of the the plugin code:

(function($) {

$.extension = function(element, options) {

    var defaults = {
        foo: 'bar',
        onFoo: function() {}
    }

    var plugin = this;

    plugin.settings = {}

    var $element = $(element),
         element = element;

    plugin.init = function() {
        plugin.settings = $.extend({}, defaults, options);
        // code goes here

        var newDiv = $(document.createElement("div"));
        newDiv.html("hello world");

        $element.append(newDiv);
    }

    plugin.foo_public_method = function() {
        // code goes here
    }

    var foo_private_method = function() {
        // code goes here
    }

            plugin.destroy = function () {
        $element.empty();
    }

    plugin.init();

}

$.fn.extension = function(options) {

    return this.each(function() {
        if (undefined == $(this).data('extension')) {
            var plugin = new $.extension(this, options);
            $(this).data('extension', plugin);
        }
    });

}

})(jQuery);

As you can see I use the jquery empty() method to erase the children of the div. It erases fine but then I am not able to re-create them.

Here is the html code used to call the plugin:

<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="js/jquery1.7.2.min.js"> </script>
<script type="text/javascript" src="js/extension.js"> </script>
</head>

<body>
<button type="button" id="destroy">Destroy</button>
<button type="button" id="create">Create</button>
<div id="random" ></div>

<script>
$('#random').extension();
$('#destroy').click(function(){
$('#random').data('extension').destroy();
});

$('#create').click(function(){
alert("hey");
$('#random').extension();
 });

 </script>

 </body>
 </html>

What am i doing wrong?

  • 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-06-06T06:49:40+00:00Added an answer on June 6, 2026 at 6:49 am

    You are not removing the old data so the plugin isn’t recreated because it won’t be == undefined

    Try

    plugin.destroy = function () {
        $element.empty().removeData("extension");
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jquery plugin boilerplate as found here . However it mentions that
I am using the jquery validation plugin from: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ How can I add a
I am using the jQuery plugin to add support for SwfUpload by steven sanderson
I'm using jquery-plugin columnizer http://welcome.totheinter.net/columnizer-jquery-plugin/ It is sometimes very slow to create the columns
I am using Jquery youtube player plugin found here: http://badsyntax.github.com/jquery-youtube-player/ The plugin allows you
I am using JQuery plugin qtip for displaying tooltip in asp.net application. Here is
I have been trying to create rotating object using jQuery and without any other
I am now using jQuery tooltip plugin to create some quick reminders for users
I wanted to create simple plugin using jquery. Also suggest me standard practice while
I'm new to Jquery plugin creation. Following jquery plugin is created using jQuery Boilerplate.

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.