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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:53:04+00:00 2026-05-30T14:53:04+00:00

Alright, I’ve got this blank array of objects. I am dynamically finding every node

  • 0

Alright, I’ve got this blank array of objects.
I am dynamically finding every node in a web page and each node is going to have it’s own object and properties.
I need a way to throw the values I need into their respective objects property

So, for example, I find the body node. I now have a special little object for this node. I need to throw pretty much everything about this little guy into his object’s properties.

So I pretty much need it to render like this:

Turning this:

<html>
    <body style="margin:0; padding:0;" title="My Title">
        <p>some text</p>
        <div class="wrapper"></div>
        <footer></footer>
    </body>
</html>

Into this:

this.nodesInfo = [ // All nodes in the page's DOM
    {
        type: 'body', // ex: body, section, aside, div, etc.
        id: 'myID', // the Id of that element
        class: ['myClass1', 'myClass2'], // the class/class' of that element
        depth: '2', // the level in the page's DOM in which that element sits, this will be an integer
        parent: 'html', // that elements direct parent Node 
        children:['div.wrapper', 'p', 'footer'], // any child Nodes that, that element may be a parent to
        text: '', // the text inside that element if any exists
        attributes: ["style=margin:0; padding:0;", "title='My Title'"] // all attributes of this node
    }
];

It would of course cycle through each node it discovered and do this for each node accordingly, until it ran out of nodes.

The class, children, and attributes properties are arrays for the simple possibility of multiples of any of these. Everything else is just a string since a node can’t have more than one ID, title, or direct parent tag.

If a node does not contain some of these properties then that property would remain blank/null/undefined.


My question is simple. Is this possible, if not would I instead have to create each object individually and the push them into my nodesInfo array?

I think the easiest way to go about this would be making an object of each Node and then pushing them all (once they are all created) into an array.

  • 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-05-30T14:53:05+00:00Added an answer on May 30, 2026 at 2:53 pm

    I was building something like this the other night. This should work and you can add more stuff easily. http://jsfiddle.net/elclanrs/UHbMa/

    $.fn.buildTree = function() {
        var tree = {};
        this.find('*').andSelf().each(function(i, v) {
            var parents = $(this).parents().length - 1,
                depth = 0;
            while (depth < parents) {
                depth++;
            }
            tree[v.tagName.toLowerCase() + '(' + i + ')'] = {
                id: (v.id) ? '#' + v.id : '',
                className: (v.className) ? '.' + v.className.replace(' ', '.') : '',
                depth: depth
            };
        });
        return tree;
    };
    
    
    // Then you can do this...
    
    var tree = $('#element').buildTree();
    for (var tag in tree) {
        // Get your variables
        var tag.match(/\w+/), // Get rid of `(n)`
            id = tree[tag].id,
            className = tree[tag].className,
            depth = tree[tag].depth;
        html = 'something'; 
    
        // Bla bla
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, hoping someone can help. I've got a page used to search for employees.
Alright, I'm trying to create textviews dynamically with strings i have in an array.
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright, i have read many different views on how to do this with no
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright, here is my problem i'm trying to solve. I have an index page
Alright I am practicing using cURL to login to different webservices. For this pariticular
Alright, I'm extremely new to programming so odds are this is a really easy

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.