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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:06:10+00:00 2026-06-17T04:06:10+00:00

I have a link and a table row that have matching classes. When the

  • 0

I have a link and a table row that have matching classes. When the link is clicked, I would like to change the background color of the row with the same class. For each case, there will be only one row with the same class.

Here is my current function.

   <script type="text/javascript">

function check(x) {
    elements = document.getElementsByClassName(x);
    for (var i = 0; i < elements.length; i++) {
        elements[i].bgColor="blue";
    }
}
</script>

Here is a part of the table row script:

<tr class="alt1 12">
<td width="50" height="55">
<img src="iPhone/statusicon/12.png" alt="" id="forum_statusicon_12" border="0"></td>
<td>
<div class="forumtitle">
<a class="forumtitle 12" href="forumdisplay.php?f=12" action="async" onclick="check(this.className.split(' ')[1])">News and Current Events</a></div>
</td>
<td width="25">
<div class="forumarrow"><img src="iPhone/chevron.png" alt="" border="0"></div>
</td>
</tr>

The table row has two classes, and I need the second one (the number) to be what is addressed. The current code gives the error “An invalid or illegal string was specified”

  • 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-17T04:06:12+00:00Added an answer on June 17, 2026 at 4:06 am

    You have several errors. You mixed classes with ids and also the class property is actually className

    <script type="text/javascript">
    
    function check(x) {
        elements = document.getElementsByClassName(x);
        for (var i = 0; i < elements.length; i++) {
            elements[i].style.backgroundColor="blue";
        }
    }
    
    </script>
    
    <a href="#" class="first" onclick="check(this.className)">change first row</a>
    <a href="#" class="second" onclick="check(this.className)">change second</a>
    <!--        FIX ( id -> class )                FIX ( class -> className ) -->
    <table>
    <tr class="first">
    <td>test1</td>
    </tr>
    
    
    <tr class="second">
    <!--FIX ( id -> class ) -->
    <td>test2</td>
    </tr>
    </table>
    

    Check this jsfiddle

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

Sidebar

Related Questions

I have a table row that has background color on hover. When user clicks
I have a table row that contains a link in it. I set the
I have a table that's sortable. Within each row is a link that dynamically
Suppose I have <table> <tr> <td><a class='ilink'> link text </a></td> <td></td> <td></td> <tr> <tr>
I have 23(column)x6(row) table and change the row with link_to_remote function. each tr tag
I currently have a table with rows that contain a clickable link. When a
I have a table-row that has a JavaScript action attached to mouse clicks anywhere
I have a link in each table row to view a record in more
I have an app that has posts, tags, and a tag_ref link table. I
I have a HTML table like this, <table> <tr class=AltTR> <td> First TD </td>

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.