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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:50:26+00:00 2026-06-14T22:50:26+00:00

This should be a nice little puzzle, and hopefully solvable by jQuery. Here is

  • 0

This should be a nice little puzzle, and hopefully solvable by jQuery. Here is a self explanatory jsFiddle. Note that I am looking for a generic solution to traverse the elements of interest in the dom based on where they are in the dom tree. I provide this reduced case as an example, so you can test your solutions against it and it is also easier to understand.

The DOM:

<div class="element" value="Hi5!">
    <div class="element" value="Zero"></div>
    <div class="junk" value="no no!"></div>
    <div class="element" value="Four">
        <div class="element" value="One"></div>
        <div class="element" value="Three">
            <div class="element" value="Two"></div>
        </div>
    </div>
    <div class="element" value="Five"></div>
</div>

The code I’v got which prints elements in an undesired order:

$(document).ready(function(){
    console.log("ready");
    $(".element").each(function(index, item){
       console.log(index + " | ",  item.getAttribute('value'));
    });
});

The current output:

ready
0 | Hi5!
1 | Zero
2 | Two
3 | One
4 | Four
5 | Three
6 | Five

How can I traverse and print the values of the nested div elements above in a postorder fashion?

Edit: thanks to @zshooter for providing a solution and pointing out a mistake in my question. Here is my updated jsFiddle ordered properly in postorder.

  • 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-14T22:50:27+00:00Added an answer on June 14, 2026 at 10:50 pm

    here you go:

    $(document).ready(function(){
        console.log("ready");
    
        $("body").children('.element').each(function(index, item) {
            visitNode(item);
        });
    });
    
    function visitNode(element) {
        $(element).children('.element').each(function(index, item) {
            visitNode(item);
        });
        console.log(element.getAttribute('value'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently used a nice little jquery script that loads images with a given
This should be so simple... I thought it would be nice to try the
I have a nice little app on the app store that does pretty well
This is going to be a nice little brainbender I think. It is a
I'm looking to write a plugin for IE that will do a little parsing
I've coded a little game, but now I realized that I should include all
I'm programming a nice little game that uses shader generated simplex noise for displaying
I know this is a little subjective, but I'm looking into the following situation:
This should be a simple one: I have an observableArray object called To in
This should be a no brainer but I have a small mystery with the

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.