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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:29:27+00:00 2026-05-11T19:29:27+00:00

I am struggling with how to select a particular element with jQuery. Conditions outlined

  • 0

I am struggling with how to select a particular element with jQuery. Conditions outlined here:

  • At the relevant point in my function, this references a span.
  • That span may be a child, grand child, or great grand child, but somewhere up the hierarchy, it’s contained by a td.
  • I’d like to select the last span inside of the td.
  • The span may be this, or it may be another span.
  • The span tags to be selected is a direct child of the containing td, so last-child is workable. However, for future flexibility a solution that doesn’t assume it’s a direct child is preferred.

So far, I am using this to select the correct parent element:

$(this).parents('td')

I don’t know how to traverse back down the DOM tree to get the final span inside of the selected td. Thanks!

Edit

Per my comments below, would also be nice to select from a span or div, whichever is last.

  • 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-11T19:29:27+00:00Added an answer on May 11, 2026 at 7:29 pm
    $(this).parents('td').children('span:last');
    

    should do the trick.

    Edit

    I didn’t notice your desire to not only deal with immediate children. If you want all decendants, then you would use

    $(this).parents('td').find('span:last')
    

    I had assumed the span would always be a child of the td.

    Final Edit

    For posterity’s sake (and to make it easier for people to find this answer in the future), since this was already accepted as the answer, Ben came up with a more elegant solution in his answer that I’m going to put here:

    $(this).closest('td').find('div,span').filter(':last')
    

    As Ben said, you must be using JQuery 1.3 for closest() to work. Good work! 🙂

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

Sidebar

Related Questions

im struggling with syntax here: hopefully this question is v simple, im just miising
I'm struggling to find the right terminology here, but if you have jQuery object...
Struggling with CSS selector. Want to select all FORM elements that are ancestors of
I'm struggling with the right type of conditional select statement here, even after searching.
I am struggling to convert this sql query SELECT feature.*, rolefeature.roleId, rolefeature.permission FROM feature
I'm struggling here a lot really. I need to prepare a form that is
I'm struggling to understand what this query is doing: SELECT branch_name, count(distinct customer_name) FROM
Greetings, I've got a query that I'm struggling with, this is the first time
I am struggling to select, and manipulate, the dropdown from the jqGrid. jQuery(#grid)... colModel:
I am struggling to get a subsonic select query to work, I am writing

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.