Welcome to the fifth part of a ten-part series that shows you how to make a drop-down browser menu that works on multiple browsers. In this part of the series, we begin an in-depth analysis of the react() function, which is the function that responds to the onmouseover event for each table cell.
When the mouse pointer is over a table cell having a SPAN element displayed, the react() function changes the background color of the table cell from brown to firebrick. While in the column, if the mouse pointer goes over another similar cell, the background of the former cell should return to brown, while that of the present cell should become firebrick.
If the SPAN element of the present cell has the ‘>’ character, the react() function displays the sub menu whose root is the present cell. If the mouse pointer goes on to another cell of the present column, the sub menu developed from the ‘>’ above should disappear. This function can produce sub menus of different levels that are related by moving the mouse pointer onto lower sub menus on items that have the ‘>’ characters.
There are seven code segments in this function. The first six are inside an if-statement. The last one is outside the if-statement. As you know, for any SPAN element that is displayed, the background color of its table cell is made brown. Any of the six segments in the if-statement will only have an effect if the background color of the cell the mouse is on is brown, meaning that a SPAN element in the cell is displayed. So any of the six segments will only have an effect for a cell if that cell has a SPAN element displayed.
The First Code Segment
This segment gets the column number of the cell in the table from the tdID parameter (whose argument has the ID of the table cell). We need this column number later.
The Second Code Segment
As we said above, when the mouse pointer is over a cell whose background color is brown, the background color will be made firebrick. Now, if the mouse pointer goes over another cell whose background color is brown in the same column, the firebrick color of the previous cell has to be turned back to brown. The segment turns all the background colors in the column to brown. By doing this, the background color of the previous cell is turned to brown. More details on this later!