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

  • Home
  • SEARCH
  • 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 8591415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:31:24+00:00 2026-06-11T23:31:24+00:00

Given the following HTML, what jQuery selector would select the last ‘blah blah’ span

  • 0

Given the following HTML, what jQuery selector would select the last ‘blah blah’ span but not the first?

<div class='d1'>
  <span>
    <a>blee
      <span> <!-- don't select this span -->
        <span>blah</span> blah
      </span>
    </a>
  </span>
</div>

<br/>

<div class='d1'>
  <span>
    <a>blee
      <span> <!-- select this span -->
        blah blah
      </span>
    </a>
  </span>
</div>

I’ve tried variations using not() but can’t figure it out. It seems like what I need is a selector that finds the first span, but then excludes it if it contains another span. Something like:

$('.d1 span a span').not(':has("span")')

but that doesn’t do it. What am I missing?

  • 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-11T23:31:25+00:00Added an answer on June 11, 2026 at 11:31 pm

    If I’ve understood your question correctly, all you’re missing is a child combinator:

    $('.d1 span a > span').not(':has("span")')
    

    Here’s a working example.

    The reason you need this is that .d1 span a span will match both span descendants of the a element in the first .d1 element. The .not() call will exclude the outer one, but the inner one will still be part of the matched set. By adding the child combinator, only the outer span is selected, and then removed by the call to .not().

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

Sidebar

Related Questions

Given the following HTML: <select id=addSelection> <option value=Original Value>Original Value</option> </select> I would like
Given the following html table, I would like to control the width of the
Given the following HTML form: <form id=myform> Company: <input type=text name=Company value=ACME, INC./> First
Given the following HTML fragment: <p id=para>hello &lt;world&gt;</p> The jQuery .text() and .html() methods
Given the following HTML file: <!DOCTYPE html5> <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js type=text/javascript></script> <script type=text/javascript>
Given the following HTML-Fragment: <div> <p> abc <span id=x>[</span> def <br /> ghi </p>
Given following html code: <ul> <li> <a href=somelink> <span class='someIconCss'></span> <span>home</span> </a> </li> [possibly
Using jQuery 1.6.1 , given I have the following HTML: <div class=control> <label>My Control</label>
Given the following HTML: <div id=table-filters> <ul> <li class=active>blah</li> <li>blah</li> <li>blah</li> <li>blah</li> </ul> </div>
Given the following HTML on a page: <div class='test'> <p><span id='id1' class='test1 test2 test3'>test

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.