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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:37:29+00:00 2026-05-21T21:37:29+00:00

I have two tables. The first is one row high and contains 7 tds.

  • 0

I have two tables. The first is one row high and contains 7 tds.

The second is 6 rows high and contains 7 tds.

When a user clicks a td in the first table, the last cell in table 2 in the corresponding column that has class ‘x’, has class ‘x’ removed and class ‘y’ added.

So next time when the same column is clicked, the cell above it would have class ‘x’ removed and class ‘y’ added, and so on…

I have managed to select the corresponding column using a plugin that allows you to select ‘nth-col’:

$('#table1 td').click(function(){

    var col = ($(this).index()+1);

    $('#table2 td:nth-col('+col+')').removeClass('x').addClass('y');

});

But just cant figure out how to select the row!

If you are wondering what I’m going on about then basically I’m trying to make connect four.

  • 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-21T21:37:29+00:00Added an answer on May 21, 2026 at 9:37 pm

    You can do it without any plugins. Go through the rows in reverse order, check the Nth td element. Exit from the loop after the first one you’ve found. This is a simple solution, might not be properly optimised to handle thousands of rows/columns though. 🙂

    Live demo: http://jsfiddle.net/yydZ3/1/

    //Set all classes to x
    $('td').addClass('x');
    
    $('td').click(function(){
        var $this = $(this);
        var col = $this.index();
    
        //Iterate through rows in reverse order
        $($('tr').get().reverse()).each(function(){
            var $cell = $(this).find('td:eq('+col+')');
            if($cell.hasClass('x')){
                //Found one, this must be the last in this column
                $cell.removeClass('x').addClass('y');
    
                //Exit out of each loop
                return false;
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two table views, when user clicks one cell of the first, second
I have two tables set up. The first table contains a listing of apartments,
i have two data tables with the same structure the first one has one
I have a tree table with two columns on a page. The first one
I have a table inside a form. It has two columns, the first one
I have two tables. The first table has a column with a lot of
I have two tables on my page and they appear side-by-side. The first one
I have two datasets, first one is generic, second one is typed. I'm trying
I have two tables with hierarchyid fields, one of which is a staging table
I have the same trigger on two tables. The first one: CREATE TRIGGER updateURL1

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.