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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:55:18+00:00 2026-06-12T14:55:18+00:00

Not sure if the title is right, please suggest changes if you disagree. I

  • 0

Not sure if the title is right, please suggest changes if you disagree.

I was working with content loaded via jquery (.load()) into a div. I had to remove couple items from the loaded content. I’ve done so in the same manner as in the jsfiddle example I wrote ( http://jsfiddle.net/AzxaL/12 ). This one does not use load() function which creates id duplication, but this is irrelevant.

The question is: why one work and another does not and what needs to change in
else if(this.tagName == ‘H2’) {
$(this).remove();
}
of the not working example?

To save you hunting down differences, the only one is in the /* line of interest */

Working

$('#copy_working_box').html($('#copy_working_box').children('#wrapper').children()).fadeIn(300);

Not working

$('#copy_working_not_box').html(content).fadeIn(300);

Also, please notice that in the not working example the div#subcontent does get removed it is only the h2 that is not.

P.S. I’m looking for clarification as I understand that this issue exists only because of my flawed understanding of how this example works.

Thanks in advance.

  • 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-12T14:55:19+00:00Added an answer on June 12, 2026 at 2:55 pm

    When you do this:

    var content = $('#copy_working_not_box').children('#wrapper').children();
    

    you get a jQuery object containing a list of elements at the time the code is run. That list isn’t dynamic, so removing one (or more) of those elements from the DOM (using .remove()) doesn’t update the list of elements in the object. However, changes to the content of those elements are reflected as your jQuery object contains references to the DOM elements.


    When you select elements using the jQuery function, in this case with the following code:

    var content = $('#copy_working_not_box').children('#wrapper').children();
    

    what you end up with is a jQuery object containing the references to the corresponding DOM elements. jQuery objects are array-like (they have a length property, and individual elements can be accessed using the square bracket notation [0]) so for our purposes we can think of it simply as an array of elements.

    Given the HTML that we’re working with, that array would consist of a <h2> element and a <div> element with the id of content. For the purposes of illustration, we’ll represent that like so:

    [<h2>, <div#content>]
    

    Now, we’re dealing with two cases in your code.

    1. Removing an element from the DOM that’s a descendent of a DOM element in our array (jQuery object).
    2. Removing an element from the DOM that’s one of the DOM elements in our array.

    In case one, we start with the reference to the element in our jQuery object; that’s the <div#content> element. We then access its children – [<p>, <div#subcontent>], filter that down to just the <div#subcontent> and remove it. Since our array still has a reference to <div#content>, and that in turn has references to its descendents, this change to the DOM will affect it (the reference to the child <div#subcontent> is removed from <div#content>).

    In case two, we start with the reference to the element in our jQuery object; that’s the <h2> element. We then simply remove this element – that removes it from the DOM, so any references to it in other DOM elements (i.e. its ancestors) will be updated. However, we still have a reference to the DOM element itself stored in our jQuery object.

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

Sidebar

Related Questions

I'm not sure that title conveys my meaning, please change it if you can
Not sure if that the right title for the question, but what I'm trying
I am not sure if I have set the right title for this post
I'm not sure if the title is correct (please comment if it is not).
Someone please recommend a better title for this question. I'm not sure what to
Not sure if the title is quite right for the question but I can't
I'm not to sure if my title is right. What I'm doing is writing
Ok, first of all, I'm not even sure the title is right, if so,
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
I'm not sure that title is worded very well, but not sure how else

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.