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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:41:28+00:00 2026-06-04T10:41:28+00:00

I need to add a class to a tr when it contains td ‘s

  • 0

I need to add a class to a tr when it contains td‘s that contain certain values.

Using the answer to this question on SO, I thought I found the solution, but it doesn’t seem to work on rows that contains multiple columns – it only works if there is a single td.

How can I identify the table rows that contain columns with certain values, among other columns? Please note that the columns will not always be in certain order, so it must be a dynamic answer.

The jsFiddle

<table>
    <tr>
        <td>Hey!</td>
        <td>Other column</td>
        <td>Yo!</td>
        <td>Other column2</td>        
    </tr>
</table>

<script type="text/javascript">
$('tr').each(function(){
 if (($(this).find('td').text() == 'Hey!' ) && ($(this).find('td').text() == 'Yo!' ))
 {
     alert('here');
     $(this).addClass('disabled');
 }
});
</script>
  • 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-04T10:41:30+00:00Added an answer on June 4, 2026 at 10:41 am

    As others have mentioned, use jQuery’s :contains(text) selector:

    $('tr').each(function(){
       if($('td:contains("Hey!")', this).length && $('td:contains("Yo!")', this).length){       
            alert('here');
            $(this).addClass('disabled');
        }
    });
    

    Something like that.

    Edit

    Updated my answer to use length instead of jQuery’s size() function. Kudos to those who posted evidence to support the notion that using length is faster. After doing some basic research of my own, came across this in the jQuery docs:

    The .size() method is functionally equivalent to the .length property;
    however, the .length property is preferred because it does not have
    the overhead of a function call.

    Given that, plus the test case below, I’m sold. Wonder why size() even exists? My thought was that it was because some objects returned by jQuery aren’t arrays but only behave like arrays, and that given that using size() was preferable. Seems that the later, at least, is not the case.

    Cheers

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

Sidebar

Related Questions

I need to add and delete class on an element having multiple classes: This
I am working with a Class that contains constants or parameter values that all
I have a class that I need to binary serialize. The class contains one
I have two user controls that need to add a class atribute to the
I need to add Workflows to an existing solution, which already contains a class
I have a class that contains some data, and I would like to add
I have a static class that contains my database logic. This class is used
I need to add a class to the list item that matches document.title. My
I need to add a class to a div based on how cookies are
I need to add a CSS class to the TR (or multiple TR's) of

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.