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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:39:36+00:00 2026-05-31T02:39:36+00:00

I need to be able to apply a style to all cells in the

  • 0

I need to be able to apply a style to all cells in the table, except cells in the current column.

I am trying to do something like this but it does not seem to work. What am I missing?

    var col = $(this).parent().children().index($(this));
    $("#myTable td:nth-child(:not(col-1))").addClass("myClass");

    <table id="myTable">
    <tr>
        <td>col 1</td>
        <td>col 2</td>
    </tr>
    <tr>
        <td><span class="click">click</span></td>
        <td><span class="click">click</span></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-05-31T02:39:38+00:00Added an answer on May 31, 2026 at 2:39 am
    //bind click event handler to the `.click` elements
    $('#myTable').find('.click').on('click', function () {
    
        //remove class from all TDs
        $('#myTable').find('td').removeClass('myClass');
    
        //get the index of the clicked element based on its parents siblings
        var index = $(this).closest('td').index();
    
        //iterate though each TD element in the table and add the class to it if it isn't the same index as the clicked element
        $.each($('#myTable').find('tr').children(), function () {
            if ($(this).index() != index) {
                $(this).addClass('myClass');
            }
        });
    });
    

    Here is a demo: http://jsfiddle.net/hU5qW/1/

    This removes the custom class from all the TD elements, then add it to the ones not in the column with the SPAN clicked. Note that if you call .index() on an element, you will get the index of that element based on its sibling elements.

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

Sidebar

Related Questions

Sorry for asking something basic here but I have not been able to apply
This is what I've got so far. I need to be able to apply
I know that the web is full of questions like this one, but I
I need to be able to apply an expression of a property to a
I'm creating something akin to a 3D map, where I need to be able
I've created a scrollbar skin that I'm able to apply to all List components
Possible Duplicate: Apply style in a table to specific columns within the th and
I have code that I'd like to run that looks something like this pseudocode:
How to apply style (image) for browse button? I need to give image for
I have a scrollable area that contains popup menus. Conceptually, something like this: <div

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.