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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:35:49+00:00 2026-06-05T13:35:49+00:00

If i fetched all elements of HTML doc and store them in an array.

  • 0

If i fetched all elements of HTML doc and store them in an array.
Now suppose i delete some element using jquery remove() method. I know it would delete its sub-child too. Now i want to traverse the list and want to know which child elements are deleted too.
Look at this code :-

$(document).ready(function() {
        var list = $('*');
        for (var i=0; i<list.length; i++) {
            console.log(i + " " + list[i].tagName);
        }
        $("table").remove();
        for (var i=0; i<list.length; i++) {
            if ($(list[i]).parent().length == 0) console.log(list[i].tagName + "does not exist in dom now");
            else console.log(i + " " + list[i].tagName + " " + $(list[i]).parent().get(0).tagName);
        }
    });

HTML part is :-

<div>
    <table>
        <tr>
            <td> Hi this is Sachin </td>
            <td> Hi this is Rahul </td>
        </tr>
    </table>
</div>

And the output I am receiving is :_

0 HTML parent.html:9
1 HEAD parent.html:9
2 SCRIPT parent.html:9
3 SCRIPT parent.html:9
4 BODY parent.html:9
5 DIV parent.html:9
6 TABLE parent.html:9
7 TBODY parent.html:9
8 TR parent.html:9
9 TD parent.html:9
10 TD parent.html:9
0 HTML undefined parent.html:14
1 HEAD HTML parent.html:14
2 SCRIPT HEAD parent.html:14
3 SCRIPT HEAD parent.html:14
4 BODY HTML parent.html:14
5 DIV BODY parent.html:14
TABLEdoes not exist in dom now parent.html:13
7 TBODY TABLE parent.html:14
8 TR TBODY parent.html:14
9 TD TR parent.html:14
10 TD TR 

I don’t understand why td and tr are showing their parents. They would be considered as deleted too. Is there any other way to find out which are the deleted items in my list now.
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-05T13:35:51+00:00Added an answer on June 5, 2026 at 1:35 pm

    The problem is your check to see if an element has a parent or not:

    if ($(list[i]).parent().length == 0)
    

    Just because you have removed an element from the DOM doesn’t mean its descendants have been removed from that element. They have been removed from the DOM (since their parent has), but they all still have that parent.

    You could use closest to check if the element has a body ancestor instead:

    if ($(list[i]).closest("body").length == 0)
    

    Since the elements are no longer in the DOM, they shouldn’t have a body ancestor.


    As a side note, since 0 evaluates to false, you can simplify your condition a little:

    if (!$(list[i]).closest("body").length)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

`I have fetched all the pages of users using manage_page permission, using this code
i wrote a simle webcrawler. i fetched all the websites and but them on
My problem is with using github and Egit. Egit fetched all of my repository
I have some Core Data entries which are all fetched and thrown into an
Hi i am using scrapy to scrape the sites I had written spider,fetched all
On my setup, the ids of all entries will be fetched (e.g. assigned to
I'm using CodeIgniter and I got a model that fetches let's say all recipes
I have fetched images and text as listview from database.now on clicking the particular
I have fetched the contents of a table in array of object. And the
I am using a combination of PHP, jQuery and Spry to serve a series

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.