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

The Archive Base Latest Questions

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

<tr> <th scope=row> <span id=home_location_indicator>(Home)</span> </th> <td> <span class=postal_code_display>…</span> </td> <td><input value=1 name=location_select type=radio

  • 0
<tr>
    <th scope="row">
        <span id="home_location_indicator">(Home)</span>
    </th>
    <td>
        <span class="postal_code_display">...</span>
    </td>
    <td><input value="1" name="location_select" type="radio" /></td>
</tr>

Say, I have a <table> that contains a couple <tr>‘s like the one above. Among the <tr>‘s, there is only one that has <span id="home_location_indicator">(Home)</span>.

I am trying to decide on the approach to take for retrieving the value of the input name="location_select" that belongs to the <tr> containing <span id="home_location_indicator">.

Here are the two approaches I can think of:

  1. $("tr").has("#home_location_indicator").find('input[name="location_select"]').val()
  2. $("#home_location_indicator").parents("tr").find('input[name="location_select"]').val()

Which one is a better approach? And why? Or does it even matter?

  • 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:32:20+00:00Added an answer on June 1, 2026 at 5:32 pm

    The best approach would be to use .closest() instead of .parents(), because it will stop traversing once it finds a match.

    $("#home_location_indicator") // ID, very fast
         .closest("tr") // Upwards traversal, fast, stops at tr
         .find(':radio[name="location_select"]').val() // Find, slow-ish
    

    This is much better than the top-down approach:

    $("tr") // getElementsByTagName, very fast
        .has("#home_location_indicator") // traverse EVERY tr ALL the way down, very slow!
        .find('input[name="location_select"]').val() // Find, slow-ish
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This question is narrower in scope than this question I asked earlier.) Say I
How to design the scope method to let it actually puts row.city? row.scope do
I insert a value / new row and I need the ID, but I
So selecting grid row value is easy: handler: function(widget, event){ rec = grid.getSelectionModel().getSelection()[0]; console.log(rec.get('amount')
Following code iterates through many data-rows, calcs some score per row and then sorts
Global scope allows you to use a variable in a function that was defined
The scope of my question is solely ASP.NET, as the answer may be different
The scope of this is that we have three main projects. Some of the
What is the scope of variables in javascript? Do they have the same scope
Within the scope of a Rails controller or a view: How can I query

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.