Welcome to the fifth part of a nine-part series that will show you how to build a browser menu. The aim of this series is to come up with a menu code that you can use with the majority, if not all, browsers without taking the particularities of a browser into consideration. We spent significant time on the previous parts on the layout; now we will get down to the code.
Functions for a Menu for All Browsers - The remove3NumID() Function Details (Page 4 of 5 )
Let us talk about the remove3NumID() function and then the remove2NumID() function before we talk about the react() function. The remove3NumID() function removes any sub menu whose number part of the table ID is made up of three digits. This is the function:
This function is called only under special circumstances. There are three for-loops. Each for-loop is for one digit. Each for-loop iterates from the index number zero to the index number 4. These five iterations are for the maximum of five menu items that our example can have for a sub menu. All the statements are in the innermost for-loop.
IDs of all possible three-digit combinations for our example are formed as the program goes through the three for-loops, from index zero to 4. The first statement in the inner for-loop forms the ID. The next statement first checks if that ID exists (for our example). If it does, then two statements are executed. The first of the two statements gives a value of "hidden" to the visibility property of the corresponding table. The second statement removes the table by giving the value of "none" to the display property of the table.
The first statement (hidden) is not really necessary. However, if you do not have it, Internet Explorer may not remove the table. The other browsers do not need the statement.