Home arrow HTML arrow Page 3 - Completing the React Function of a Common Browser Menu
HTML

Completing the React Function of a Common Browser Menu


In this eighth part of a ten-part series on building a common browser menu, we treat the last code segment of the react() function. This is the last part of the in-depth analysis we are making of the react() function.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 24, 2009
TABLE OF CONTENTS:
  1. · Completing the React Function of a Common Browser Menu
  2. · Explanation of the Seventh Code Segment
  3. · Explanation of the Seventh Code Segment Continued
  4. · Cleaning Up for Previous Sub Menus

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Completing the React Function of a Common Browser Menu - Explanation of the Seventh Code Segment Continued
(Page 3 of 4 )

The next statement we have is an if-statement. The rest of the statements in this code segment are in this if-block. We have to know whether or not the value of the otherSpanNo variable is for a SPAN element that has to be displayed. At each iteration, we want the number for the SPAN element that does not have to be displayed.

When you have a sub menu, in order to have another sub menu, your mouse pointer has to move to some ancestor menu item. This means that the number of digits in a SPAN number whose element you want to remove will always be greater than the number of digits of the SPAN number for the SPAN element in the current cell. The condition of the if-statement here tests for this. If the result of the test is true, then we can proceed to remove the SPAN element at that iteration. In other words if the result is true, the statements in the if-block will be executed. However, before we remove the SPAN elements, there are a few other things to consider.

If a SPAN element of a sub menu has to be displayed, then the digits that its SPAN numbers begin with have to be the same as the digits of the SPAN number (spanNo) of the current cell, in the same order. If this is not the case for any cell in the iteration, then any such SPAN element displayed has to be removed (un-displayed with "none").

We use the JavaScript String slice method. This method gets a portion of a string and returns that portion. It needs the start index and end index for the portion to be retrieved. Index counting of characters in a string begins from zero. The portion is actually copied from the original string, so the original string remains intact.

The string from which to get the portion is the otherSpanNo string. The portion sliced out has to be equal to the value of spanNo. The slice has to begin from index zero. The first statement in the if-block has the beginslice variable with a value of zero for this purpose. The length of the portion is the length of the value of spanNo. The second statement in the if-block has the endslice variable with value spanNo.length for this purpose. The next statement gets the portion of the string and assigns it to the slicedStr variable.


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 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials