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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:39:46+00:00 2026-06-13T12:39:46+00:00

My table’s <td> s contains multiple classes. I would need to find every <td>

  • 0

My table’s <td>s contains multiple classes. I would need to find every <td> that contains the given string.
For example:

<table>
    <tr>
        <td class="hello there">foo</td>
        <td class="hello here">bar</td>
        <td class="not hello">baz</td>
    </tr>
</table>

I would need to find every td containing “hello”.
Can it be done? The simple className == will only return exact matches. Of course.

  • 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-13T12:39:47+00:00Added an answer on June 13, 2026 at 12:39 pm

    That’s what getElementsByClassName is for:

    document.getElementsByClassName('hello');
    

    This’ll select any elements that have the class hello.

    Note: The class attribute contains a space separated list of class names.


    If you need to support IE8 and below, use this:

    var elements = document.getElementsByTagName("td"),
        helloElements = [],
        i = elements.length;
    
    for (i--) {
        if ( ~(' ' + elements[i].className + ' ').indexOf(' hello ') ) {
            helloElements.push(elements[i]);
        }
    }
    

    Here’s a demo: http://jsfiddle.net/AJEsp/


    As per @mplungjan’s suggestion, here’s a short explanation of the bitwise tilde (~) trick:

    The indexOf function returns an integer with the position of the found substring, so that 'abc'.indexOf('b') will return 1, 'abc'.indexOf('c') will return 2, and so forth. If the substring is not found, it will return -1.

    The ~ character is one of the bitwise operators whcih inverts all the bits. Sidestepping the complicated issue of how exactly this happens, all we need to know now is that ~-1 returns 0, while using the tilde on anything else would return a truthy value.

    So, ~'str'.indexOf('substring') can be treated as a Boolean of whether the substring was found.

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

Sidebar

Related Questions

Table locations contains locID , lat & long & name values of a certain
Table Each row represents a video that was on air at particular time on
Table A has a number of rows, only some of which have (multiple) children
table 1 id name class 1 ab A 2 cd A 3 ef B
Table UserData (UserID, Sales, Credits) I need to return the SUM of sales, sum
Table 1: Tracks Table 2: Wordlist Table 3: N:M Track has Words (trackwords) Find
Table Class Firstname Lastname mark V John Lim 60 V Wills smith 80 VI
Table Definition Model Definition Code using MyRandomizer.Models; namespace MyRandomizer { class Program { static
Table: Customer with columns Start_Time and End_Time. I need to add a new column
Table Schema For the two tables, the CREATE queries are given below: Table1: (file_path_key,

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.