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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:44:37+00:00 2026-05-26T09:44:37+00:00

I want to know how can I disable and enable the highlighting on an

  • 0

I want to know how can I disable and enable the highlighting on an HTML table using Javascript by clicking an html button.

Here are my codes:

tabletest.html

<html>
<head>
<script type="text/javascript">
 function disableTable() {
  document.getElementbyId('tblTest').disabled = true;
 }

 function enableTable() {
  document.getElementbyId('tblTest').disabled = false;
 }
</script>

<style type="text/css">
 table#tblTest {
  width: 100%;
  margin-top: 10px;
  font-family: verdana,arial,sans-serif;
  font-size:12px;
  color:#333333;
  border-width: 1px;
  border-color: #666666;
  border-collapse: collapse;
 }

 table#tblTest tr.highlight td {
  background-color: #8888ff;
 }

 table#tblTest tr.normal {
  background-color: #ffffff;
 }

 table#tblTest th {
  white-space: nowrap; 
  border-width: 1px;
  padding: 8px;
  border-style: solid;
  border-color: #666666;
  background-color: #dedede;
 }

 table#tblTest td {
  border-width: 1px;
  padding: 8px;
  border-style: solid;
  border-color: #666666;
  background-color: #ffffff;
 }
</style>
</head>

<body>
 <table id="tblTest">
  <thead>
   <tr>
    <th>Name</th>
    <th>Address</th>
   </tr>
</thead>
<tbody>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" >
        <td>Tom</td>    
        <td>UK </td>
    </tr>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" >
        <td>Hans</td>   
        <td>Germany</td>
    </tr>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" > 
        <td>Henrik</td> 
        <td>Denmark</td>
    </tr>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" >
        <td>Lionel</td> 
        <td>Italy</td>
    </tr>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" >
        <td>Ricardo</td>    
        <td>Brazil</td>
    </tr>
    <tr onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'" >
        <td>Cristiano</td>  
        <td>Portugal</td>
    </tr>
</tbody>
</table>
 <input type="button" onclick="disableTable();" value="Disable" />
 <input type="button" onclick="enableTable()" value="Enable" />
 </body>
</html>

Whenever I click the Disable button the table highlighting is still enabled.
I’m kinda new to this so I really need your help.

  • 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-26T09:44:38+00:00Added an answer on May 26, 2026 at 9:44 am
    <html>
    <head>
    <script type="text/javascript">
    disable = new Boolean();
     function highlight(a) {
      if(disable==false)a.className='highlight'
     }
    
     function normal(a) {
      a.className='normal'
     }
    </script>
    
    <style type="text/css">
     table#tblTest {
      width: 100%;
      margin-top: 10px;
      font-family: verdana,arial,sans-serif;
      font-size:12px;
      color:#333333;
      border-width: 1px;
      border-color: #666666;
      border-collapse: collapse;
     }
    
     table#tblTest tr.highlight td {
      background-color: #8888ff;
     }
    
     table#tblTest tr.normal {
      background-color: #ffffff;
     }
    
     table#tblTest th {
      white-space: nowrap; 
      border-width: 1px;
      padding: 8px;
      border-style: solid;
      border-color: #666666;
      background-color: #dedede;
     }
    
     table#tblTest td {
      border-width: 1px;
      padding: 8px;
      border-style: solid;
      border-color: #666666;
      background-color: #ffffff;
     }
    </style>
    </head>
    
    <body>
     <table id="tblTest">
      <thead>
       <tr>
        <th>Name</th>
        <th>Address</th>
       </tr>
    </thead>
    <tbody>
        <tr onMouseOver="highlight(this)" onMouseOut="normal(this)" >
            <td>Tom</td>    
            <td>UK </td>
        </tr>
        <tr onMouseOver="highlight(this)" onMouseOut="normal(this)" >
            <td>Hans</td>   
            <td>Germany</td>
        </tr>
        <tr onMouseOver="highlight(this)" onMouseOut="normal(this)" > 
            <td>Henrik</td> 
            <td>Denmark</td>
        </tr>
        <tr onMouseOver="highlight(this)" onMouseOut="normal(this)" >
            <td>Lionel</td> 
            <td>Italy</td>
        </tr>
        <tr onMouseOver="highlight(this)" onMouseOut="normal(this)" >
            <td>Ricardo</td>    
            <td>Brazil</td>
        </tr>
        <tr onMouseOver="highlight(this)" onMouseOut="normal(this)" >
            <td>Cristiano</td>  
            <td>Portugal</td>
        </tr>
    </tbody>
    </table>
     <input type="button" onclick="disable = true;" value="Disable" />
     <input type="button" onclick="disable = false;" value="Enable" />
     </body>
    </html>
    

    Fixed your code. Use a function to check if it’s disabled, if it isn’t, then highlight. If it is, then don’t. Simple enough.

    Demo

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

Sidebar

Related Questions

I know you can enable and disable payment methods using conditional actions, but I
I want to know how can I read attachment messages without using scriplets in
I know how to enable/disable comments on all pages. But how can I enable
I want to know why select file or choose file button is disable when
I want to know can we have a JPanel with a Layout other than
i want know how i can manage multiple twitter account on iOS in my
I want to know how can a retrieve a UIImage size, depending on the
I want to know how can we know the other users of Oracle 10g
I want to know how can I perform VS2008 load test from five different
I want to know how can i fill only certain columns while filling the

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.