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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:44:21+00:00 2026-06-13T13:44:21+00:00

Basically I’m trying to optimize my jQuery code by unbinding elements anytime is necessary,

  • 0

Basically I’m trying to optimize my jQuery code by unbinding elements anytime is necessary, or that I need to re-bind them, but I have a question, does “destroying” an element also destroys the event attached to that element?

$(element).bind("click", function(){...});
$(element).parent().html("");

Also I’m not sure if this is done with the .html(“”), do I have to use a .remove() to do the trick?

  • 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-13T13:44:22+00:00Added an answer on June 13, 2026 at 1:44 pm

    As long as you use jQuery methods to add/remove elements and bind events, all should be fine. When you bind an event to an element (or use something like .data()), jQuery stores this information in a place called $.cache. When you use jQuery methods to manipulate the DOM, jQuery takes care of cleaning up these things – because there really is no actual connection between the elements and $.cache. So if you added a div to the page, bound a click event to it with jQuery, then removed it with node.parentNode.removeChild(node);, $.cache is not cleaned up. If you would like evidence, look in the jQuery source for the methods like html, remove, replaceWith and similar ones, and you’ll find calls like this:

    jQuery.cleanData( elem.getElementsByTagName("*") );
    jQuery.cleanData( [ elem ] );
    

    This effectively cleans up the $.cache so that everything is taken care of. The point is that if you use the library for (everything) you do, you shouldn’t have to worry about these things.

    Using html is tricky though – be careful what you pass to it. If you want to pass it a new DOM structure, like

    var div = $("<div>")
                  .attr("id", "div1")
                  .click(function () {
                      alert("clicked");
                  });
    

    Using something like $("#container").html(div); will not actually bind that click event handler. Using something like .append will though. Just wanted to point that out. (this is unrelated to destroying/removing elements)

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

Sidebar

Related Questions

basically I have a function that resizes elements accordingly with jquery triggering the function
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
Basically I am trying to do this: <Trigger Property=Item Value={c:CollectionView.NewItemPlaceHolder}> But the syntax is
Basically I just need the effect of copying that HTML from browser window and
Basically I have some simple code that does some things for files and I'm
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically I'm wondering if I can compile code that a user inputs in a
Basically I need to verify that a certain program is not running before installation.
Basically I need to get older version of a file in the repository without
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.

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.