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.
Here we have a for-loop. The for-loop has one statement, which is an if-statement. This if-statement has other statements inside its block. The for-loop goes through the column that has the cell, which called the react() function.
For each iteration, the segment first of all checks to see if a SPAN element is displayed in a cell where it is not supposed to be displayed. How does this come about? Well, following our setup, consider the case where you have a sub menu coming out from a drop down menu. Not all the cells in the sub menu have a brown background color; that is, not all the cells display a SPAN element. If you move your mouse pointer onto one of the cells in the sub menu, the second segment of the react() function will give the color brown to all the cells in the column with the sub menu. This is not what you want; you wanted the cells that do not have the SPAN element shown to be transparent. So this segment comes in and gives back to those cells their transparent color.
In order to see if a cell in the column (sub column) is not displaying a SPAN element, the segment uses the Boolean Table. Recall that for each cell in our table that has a SPAN element displayed, the Boolean Table has the content “true” in its corresponding cell. The condition of the if-statement tests to see if this content is not “true.” If the content is not “true,” it means the background color is supposed to be transparent and there is not supposed to a SPAN element there; in that case, the statements in the if-block are executed.
Before we look at the lines in the if-block, let us talk about the statement in the if-test. The cells of the Boolean and Number Tables do not have IDs. So to address the cells, you have to use the DOM’s row and column indices (with the object reference, row and column containers). The expression on the left hand side of the assignment operator of the statement is derived from DOM principles. We have seen this kind of expression elsewhere.
It's time to take a break. I'll see you in the next part of the series.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.