Home arrow HTML arrow Page 3 - Making a Common Browser Menu React
HTML

Making a Common Browser Menu React


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.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 03, 2009
TABLE OF CONTENTS:
  1. · Making a Common Browser Menu React
  2. · Third Code Segment of the react() Function
  3. · Details of the react() Function
  4. · The Fourth Code Segment: Details

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Making a Common Browser Menu React - Details of the react() Function
(Page 3 of 4 )

The react() function begins with an if-statement. As I said, the first six code segments out of the seven code segments are in this if-statement. This is the if-test:


//react only if the background color of the table cell is brown

if (document.getElementById(tdID).style.backgroundColor == "brown")

{

}


The if-condition tests to see if the background color of the cell that called the react() function is brown; that is, if the cell has a SPAN element displayed. It uses the ID of tdID, which is the first parameter of the react() function for this.


The First Code Segment: Details

This is the code of the first code segment:


//get the column no. We need it later.

var colNo = tdID.charAt(3);

colNo = parseInt(colNo);


The ID of any table cell begins with "TD" followed by the table row number and the table column number. The first statement extracts the column number, which is at the last index position (3) of the ID string. It assigns the value to the colNo variable. The second line converts the character retrieved into an integer. We need this table column number later.

The Second Code Segment: Details

This segment sets all background colors on the column to brown. The column number retrieved above is used here. This is the segment:


//set all background colors on the column to brown first

for (i=0; i<5; i++)

{

ID = "TD" + i + colNo

document.getElementById(ID).style.backgroundColor = "brown";

}


We have a for-loop here. The segment loops through the cells of the column. For each iteration, it forms the ID of the cell. The index of the iteration is considered to be the row number. The column number is already known from the previous segment. The colNo variable holds it.

The Third Code Segment: Details

When the mouse pointer is on a cell, the react() function is called. This segment is in the react() function. It gives the cell that called the function a background color of firebrick. This is the code segment.


//give the onmouseover bar a firebrick color

document.getElementById(tdID).style.backgroundColor = "firebrick";


It uses the ID sent as the first argument of the react() function.



blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials