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

The Archive Base Latest Questions

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

Currently i am using to jquery for a table which i would like to

  • 0

Currently i am using to jquery for a table which i would like to be able to highlight the tds where i click twice. for example when i click on any td, it highlights that td in the table. When i click on another td further down in the column, it highlights all the middle too. If i click on another td in another column, it should remove the previous column and start all over again. Currently, I have explored with .find in jquery but to no avail. The only option i could think of is hard coding a id into the td and colouring individually. This i think is not efficient coding. Would appreciate any help. Thanks

<table>
<tr>
<td><td><td>
<td><td><td>
<td><td><td>
<td><td><td>
</tr>
</table>
  • 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-11T20:52:32+00:00Added an answer on June 11, 2026 at 8:52 pm

    No, no need to hardcode. Just make a check (in your td-click handler) that some siblings of this element are already highlighted. For example, if you assign a class ‘.highlight’, the query will look like this:

    $(this).siblings('.highlight');
    

    … which will return you elements from the same row only which are highlighted.

    UPDATE: Misread your question and thought you need to highlight a horizontal column actually. If it’s vertical you need to work with, add some index and nth-child to your queries:

    $('td').click(function() {
      var $this = $(this),
          index = $this.index();
      var $columnCells = $this.parents('table')
                              .find('tr td:nth-child(' + (index + 1) + ')');
      $columnCells.toggleClass('highlight');
    });
    

    Demo.

    UPDATE #2: Here’s (admittedly, a bit rough) example of the full col-highlighting code:

    $('td').click(function() {
      var $this = $(this),
          index = $this.index(),
          $table = $this.parents('table'),
          $rows  = $table.find('tr'),
          $columnCells = $rows.find('td:nth-child(' + (index + 1) + ')');
      var $hiCells = $columnCells.filter('.highlight');
      if ($hiCells.length) {
           var thisRowIndex = $this.parent().index(),
               $firstHiRow = $( $hiCells[0] ).parent(),
               firstHiIndex = $firstHiRow.index(),
               $lastHiRow  = $( $hiCells[$hiCells.length - 1] ).parent(),
               lastHiIndex = $lastHiRow.index();
          if (thisRowIndex > lastHiIndex) {
              $rows.slice(lastHiIndex, thisRowIndex + 1)
                   .find('td:nth-child(' + (index + 1) + ')').addClass('highlight');
          } else if (thisRowIndex < firstHiIndex) {
              $rows.slice(thisRowIndex, firstHiIndex)
                   .find('td:nth-child(' + (index + 1) + ')')
                   .addClass('highlight');
          }
      } else {
          $table.find('td').removeClass('highlight');
          $this.addClass('highlight');
      }
    });
    

    Demo.

    As you see, each time a cell is clicked, we get all the cells in the column, then check their highlight state. If some of them are highlighted, we get the first and the last highlighted rows, then basically perform the same op on them: 1) get all the rows that are in between the clicked row and the last highlighted one; 2) get all the cells in the same column, and 3) mark ’em! If no cells are highlighted in this column, we just remove the highlights set, then highlight the clicked cell.

    This can be streamlined quite a bit, though, if all the column numbers are cached (for example, with ‘data-column’ attribute). But the method in general, I suppose, is still the same.

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

Sidebar

Related Questions

I'm currently using jQuery Cookies plugin, and depending on which side of the page
I am currently using Jquery UI to display checkboxes, which right now, don't do
Using a simple table and jquery, how would you manually handle selection on a
I have an HTML table, to which I would like to add or remove
I have a grid that is currently using Telerik Grids, I would like to
I'm using Jquery Mobile. On my page I have a table, which I'm dynamically
I'm currently using jQuery to make a div clickable and in this div I
I'm currently using JQuery to assign colors to containers. In Chrome and IE, when
I am currently using jQuery to load a variable php layout depending on the
I am currently using jquery corner for making a div round cornered. But 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.