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

  • Home
  • SEARCH
  • 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 8883565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:50:37+00:00 2026-06-14T20:50:37+00:00

I’m working on a project in ASP and I’m not used to Javascript or

  • 0

I’m working on a project in ASP and I’m not used to Javascript or Jquery

I found some code that if I click on a row, it will change the color.

I now want to change the display to normal when I click on a row and then hide it if I click on any other row.

What I have so far

<table id="myTable" class="tablesorter"> 
<thead> 
<tr> 
    <th>INFO</th> 
</tr> 
</thead> 
<tbody> 
<tr onclick="changeMe(this);"> 
    <td>INFO</td> 
            <tr class="versionRow" style ="display:none">
                <td>INFO</td>
            </tr>
</tr> 
</tbody> 
</table> 

And my script for changing the color.

<script>
    var whosChanged = null;

    function changeMe(el) {
        el.style.backgroundColor = "#00FF00";
        el.style.color = "#000000";

        if (whosChanged != null) {
            whosChanged.style.backgroundColor = ""
            whosChanged.style.color = ""
        }

        whosChanged = el;
    }
</script>

I just want to be able to display the row with the class versionRow when I click on it.

Any ideas or suggestions? Thank you.

  • 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-14T20:50:39+00:00Added an answer on June 14, 2026 at 8:50 pm

    Here’s one approach:

    function hasClass(el, needle) {
        if (!el || !needle) {
            return false;
        }
        else {
            var classes = el.className.split(/\s+/);
            for (var i = 0, len = classes.length; i < len; i++) {
                if (classes[i] == needle) {
                    return true;
                }
            }
            return false;
        }
    }
    
    function nextElementSiblingShim(el) {
        if (!el) {
            return false;
        }
        else {
            return el.nextSibling.nodeType == 1 ? el.nextSibling : nextElementSiblingShim(el.nextSibling);
        }
    }
    
    function changeMe(el) {
        if (!el) {
            return false;
        }
        else {
            var nextElem = el.nextElementSibling || nextElementSiblingShim(el);
            if (hasClass(nextElem, 'versionRow')) {
                nextElem.style.display = window.getComputedStyle(nextElem, null).display !== 'none' ? 'none' : 'table-row';
            }
        }
    }
    
    var rows = document.getElementsByClassName('changeMe');
    
    for (var i = 0, len = rows.length; i < len; i++) {
        rows[i].onclick = function(){
            changeMe(this);
        };
    }​​​​​​
    

    This does rely on well-formed HTML, though: as noted in my comment to your question a tr is only a valid child of a table, thead, tbody and tfoot elements. It is not a valid child of another tr. You could nest a table inside of a td, but there should be no elements inside of a tr except for td and th. That said, the following HTML will allow the above script(s) to work:

    <table id="myTable" class="tablesorter">
        <thead>
            <tr>
                <th>INFO</th>
            </tr>
        </thead>
        <tbody>
            <tr class="changeMe">
                <td>INFO</td>
            </tr>
            <tr class="versionRow">
                <td>INFO</td>
            </tr>
        </tbody>
    </table>​​​​​​​
    

    JS Fiddle demo.

    Note that I’ve taken out the onclick event-handlers, to separate the behaviour from the mark-up, and, hopefully, make things more maintainable in future. I’ve also moved the (invalid) nested tr from its parent and added it as a sibling.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I am reading a book about Javascript and jQuery and using one of the
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.