SoFunction
Updated on 2025-02-28

A very simple way to achieve the highlighting effect of TD.

Copy the codeThe code is as follows:
function Menu_Init(obj){
   var tds = ("td");
    for (var i = 0; i < ; i++)
     {
       if (tds[i].className == "MenuOptions")
      {
        tds[i].onmouseover = switch_bg;
        tds[i].onmouseout = switch_bg;
      }              
      }

}
function switch_bg(e){
   if (=="MenuOptions_click") return
    = ( == "MenuOptions") ? "MenuOptions_hilite" : "MenuOptions";
 }

Menu_Init(obj) is used to initialize Table.

Required CSS
Copy the codeThe code is as follows:
.MenuOptions{
 padding:2px;
 cursor:hand;
 color:#000000;
}
.MenuOptions_hilite{
  padding:1px;
  border:outset 1px #669999;
  cursor:hand;
 color:#000000;
}


Table Demonstration
Copy the codeThe code is as follows:
<table id=MenuTools border="0" cellspacing="2" style="border:1px solid #000000;color:#000000;font-size:12px">
<tr>
<td class="MenuOptions" >Hello everyone
<td class="MenuOptions" >Easy to achieve
<td class="MenuOptions" >Please use it if you like
<td >This is not allowed to be highlighted
</tr>
</table>


Demo

[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]