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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:49:04+00:00 2026-06-05T21:49:04+00:00

I am trying to grab all the td elements between the first two that

  • 0

I am trying to grab all the td elements between the first two that have the class ‘selected’. and change the text color to green. I am using nextUntil but the problem I am facing is that when there is a new <tr> it doesn’t grab those td elements. Is there a way to ignore any <tr> tags using nextUntil? Thanks

jQuery:

var firstDate = $('table.jCalendar tbody').find($('td.selected')[0]);
var secondDate = $('table.jCalendar tbody').find($('td.selected')[1]);
$(firstDate).nextUntil(secondDate).css("color", "green");

HTML:

<table cellspacing="2" class="jCalendar"><tbody>
<tr>
   <td class="current-month weekday today unselectable">18</td>
   <td class="current-month weekday unselectable">19</td>
   <td class="current-month weekday selected">20</td>
   <td class="current-month weekday unselectable" style="color: green; ">21</td>
   <td class="current-month weekday unselectable" style="color: green; ">22</td>
   <td class="current-month weekend unselectable" style="color: green; ">23</td>
   <td class="current-month weekend unselectable" style="color: green; ">24</td>
</tr>
<tr>
   <td class="current-month weekday today unselectable">25</td>
   <td class="current-month weekday unselectable">26</td>
   <td class="current-month weekday selected">27</td>
   <td class="current-month weekday unselectable">28</td>
   <td class="current-month weekday unselectable">29</td>
   <td class="current-month weekend unselectable">30</td>
   <td class="current-month weekend unselectable">31</td>
</tr>
</tbody></table>

so to clarify i want the td elements with the texts 20 through 26 selected but 21 through 24 is only being selected. Sometimes there are more then just one set of <tr> tags between the td tags with the class selected.

  • 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-05T21:49:06+00:00Added an answer on June 5, 2026 at 9:49 pm

    My understanding is to highlight every TD regardless of row between the 2 selected class.

    Am using a class change instead of inline CSS as it is much easier to remove on subsequent selections with one line of code.

    DEMO: http://jsfiddle.net/5txeq/

    var firstRow = $('td.selected:first').parent()
    var secondRow = $('td.selected:last').parent();
    
    $('tr').slice(firstRow.index() + 1, secondRow.index()).find('td').addClass('green')
    
    firstRow.find('.selected').nextAll().andSelf().addClass('green')
    secondRow.find('.selected').prevAll().andSelf().addClass('green')
    

    Alternate shorter version:
    DEMO: http://jsfiddle.net/5txeq/2/

    var $cells = $('tbody td'),
        idx_1 = $cells.index($('td.selected:first')),
        idx_2 = $cells.index($('td.selected:last'));
    
    $cells.slice(idx_1, idx_2 + 1).addClass('green');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to grab all the id's that are part_number and feed them
I'm writing an XPath expression in Java, and am trying to grab all elements
I have an XPath query that's trying to grab the parent of a specific
Im trying to grab all data(text) coming from a URL which is constantly sending
I'm trying to grab all the links and their content from a text, but
Im trying to figure out how to grab all connectionStrings from a web.config that
I am trying to grab all selected items in the following select multiple and
I am trying to grab elements from HTML source based on the class or
I'm trying to grab all the URLs of my Facebook photos. I first load
Im trying to first grab all the links from a page, when get 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.