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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:54:49+00:00 2026-06-01T17:54:49+00:00

Given a repeating, nested element structure, for example: <div class=A> <span class=B></span> <span class=B></span>

  • 0

Given a repeating, nested element structure, for example:

<div class="A">

  <span class="B></span>
  <span class="B></span>

  <span class="B">
     <div class="A">
        <span class="B"></span>
     </div class="A">
  </span>

</div>

How can I select the last <span class="B"></span> that is a direct child of the root <div class="A"></div> element?

I tired:

div.A > class.B

…but (correctly) this also matches the last element which is not a direct child of the root <div class="A"></div> element.

  • 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-01T17:54:51+00:00Added an answer on June 1, 2026 at 5:54 pm

    you could either add some id, classes, or a data-level object in order to make the nesting search easier, or you could do this slightly hackish version:

    $('div.A').first().children('span.B').last();
    

    I would suggesting adding a data-level, id, or other class to handle the level though.

    For example, change your HTML to:

    <div class="A" data-level="first">
    
      <span class="B" data-level="second"></span>
      <span class="B" data-level="second"></span>
    
      <span class="B" data-level="second">
         <div class="A" data-level="third">
            <span class="B" data-level="fourth"></span>
         </div>
      </span>
    
    </div>
    

    and you can do things like:

    $('span.B[data-level="second"]').last();
    

    etc.

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

Sidebar

Related Questions

Given a database that has numerous repeating columns used for auditing and versioning, what
Given long long int x, y; , I want a function that can compare
given series of DIVs w/unique ID as in: <div id=2988> <div class=site>YaHoot.com</div> <div class=logo>/images/yahootLogo.jpg</div>
Given a string S of length N find longest substring without repeating characters. Example:
I have been given a task that can be simplified to this scenario: Customers
The problem: Using ASp.NET MVC for reporting. Given: 1. A report that is tabular
Given this class: class Foo { readonly ILog log; public Foo(ILog log) { this.log
Given the following example SWF: Sample Notice how with the words enthusiast at the
Let's say I want to find all sets of 5 single-digit, non-repeating numbers that
I'm using Python to infinitely iterate over a list, repeating each element in 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.