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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:00:00+00:00 2026-05-26T13:00:00+00:00

I was wondering how jQuery traverses the DOM when you use a selector. Does

  • 0

I was wondering how jQuery traverses the DOM when you use a selector.
Does it look up each “first level” element, and then look inside each one of them? Or does it look at every children of those “first level” elements one by one?

Let me explain what i imagined with some quick examples, given the following selector :

$("div p#target")

Does it proceed more like :

[1] <div>
    [3] <div>
        [5] <p id="target"></p>
        </div>
    </div>
[2] <div>
    [4] <div>
            <p></p>
        </div>
    </div>

Or like :

[1] <div>
    [2] <div>
        [3] <p id="target"></p>
        </div>
    </div>
    <div>
        <div>
            <p></p>
        </div>
    </div>
  • 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-26T13:00:00+00:00Added an answer on May 26, 2026 at 1:00 pm

    Traversal happens in the same order the elements are in the DOM:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
        <head>
            <title>query traversal order</title>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
        </head>
        <body>
            <ul>
                <li id="parent1">
                    <ul>
                        <li id="child1"></li>
                        <li id="child2"></li>
                    </ul>
                </li>
                <li id="parent2">
                    <ul>
                        <li id="child3"></li>
                        <li id="child4"></li>
                    </ul>
                </li>
            </ul>
            <script type="text/javascript">
                // keep a list of ids
                var arr = [];
                // loop over all li elements
                $('li').each(function(){
                    // add their id to the array
                    arr.push($(this).attr('id'));
                });
                // show contents of the array
                alert(arr.join(', '));
            </script>
        </body>
    </html>
    

    This will alert “parent1, child1, child2, parent2, child3, child4”;

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

Sidebar

Related Questions

I was wondering whether jQuery builds indexes into the DOM to speed up selector
I was wondering what JQuery actually does to a <div> when you set it
Just wondering if anyone knows of a jQuery sortable plugin that I can use
I'm wondering if there's a jQuery-like css selector that can be used in C#.
I am wondering what the googlebot will see when we use jQuery for rounded
I'm wondering how to do this with JQuery. I have a menu where each
i was wondering i am having jQuery Javascript Javascript Timers CSS DIVs    inside DIVs
I was always wondering how to use jquery. Should I use it for everything,
I'm wondering if I can use jQuery to recode HTML that's entered into a
I use jQuery UI around my site and am wondering how I can use

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.