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 8962833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:13:19+00:00 2026-06-15T16:13:19+00:00

I have issue with my plugin, because I need a way to update if

  • 0

I have issue with my plugin, because I need a way to update if new elements are added to the DOM I added a update methods,
if I start the plugin all goes well, everything works perfect, not issues, no error, but once I add a new elelemnt(div with class box)
to the DOM things goes wrong, the update works, but the click events seem to fire multiple times now, so if I add a new element the event runs
twice, if I add 2 elements to the DOM, the events runs 3 times….and so on. I am not that good at Js, so I am stuck at this, I have tried a lot but nothing seems to work.

Elements that are newly added work fine, but if I add some more new elements they will have the same issues.

I added below a small preview, as my plugin is custom an big I only posted the parts that have issues(made them easy to understand).

The update method is needed, new elements(.box) need to be updated(add new code to the .box)

the HTML code

 <div id="container">

  <div class="box">
      <a href="#" class="link1">link 1</a>
      <a href="#" class="link1">link 2</a>
      <div>content goes here...</div>
  </div>

  <div class="box">
      <a href="#" class="link1">link 1</a>
      <a href="#" class="link1">link 2</a>
      <div>content goes here...</div>
  </div>

  <div class="box">
      <a href="#" class="link1">link 1</a>
      <a href="#" class="link1">link 2</a>
      <div>content goes here...</div>
  </div>
</div>

inline script

  $('#container').myplugin01();

  $('#somelink').click(function(e){
      $('#container').append('<div class="box"><a href="#" class="link1">link 1</a><a href="#" class="link1">link 2</a><div>content goes here...</div></div>'); 

      $('#container').myplugin01('update');
  });

the plugin

  ;(function($, window, document, undefined){

      //"use strict"; // jshint ;_;

      var pluginName = 'myplugin01';

      var Plugin = function(element, options){
          this.init(element, options);
      };

      Plugin.prototype = {

          init: function(element, options){

              this.elm     = $(element);
              this.options = $.extend({}, $.fn[pluginName].options, options);


              // example 1: animation
              $('#container').children('.box').on("click", ".link1", function(e){
                  $(this).parent().children('div').animate({height: 'toggle'},400)
              });

              // example 2: wrapping
              $('#container').children('.box').on("click", ".link2", function(e){
                  $(this).parent().wrap('<div class="wrapped"></div>')
              });


              this.update();
          },

          update: function(){
              $('#container').children('.box').addClass('someclass');

              // more code here...
          }
      };

      $.fn[pluginName] = function(option) {
          var options = typeof option == "object" && option;

          return this.each(function() {
              var $this = $(this);
              var data  = new Plugin($this, options);

              if(!$.data($this, pluginName)){           
                  $.data($this, pluginName, data);
              }

              if(typeof option == 'string'){
                  data[option]();
              }

          });
      };

      /**
      * Default settings(dont change).
      * You can globally override these options
      * by using $.fn.pluginName.key = 'value';
      **/
      $.fn[pluginName].options = {
          name: 'world' 
      };


  })(jQuery, window, document);
  • 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-15T16:13:20+00:00Added an answer on June 15, 2026 at 4:13 pm

    If you bind events more than once this problem will occur.

     // inline script
      $('#container').myplugin01();// binding first time
    
      $('#somelink').click(function(e){
          $('#container').append('<div class="box"><a href="#" class="link1">link 1</a><a href="#" class="link1">link 2</a><div>content goes here...</div></div>'); 
    
          $('#container').myplugin01('update');// binding second time
       // We suggest you to unbind here and rebind it.
    
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue with Greasemonkey, it doesn't update my script automatically (probably because
I'm writing a WP plugin and have an issue. In the pludin's settings area,
We are new to ROR, We have issue in creating Login/Logout process in ROR
I have setup the BlackBerry plugin in Eclipse and then added blackberry nature per
every one..i have one issue while runing phonegap facebook plugin.i have Downloaded phonegap facebook
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
Share your ideas please! I have issue to check the folder and convert a
Have an issue with marshall and unmarshall readers and writers. So here it is.
I have an issue with jquery and history.back(): I got a link: <a href=#

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.