| Site Map | WizTools.org | jCraze Blog |
![]() |
Subhash's Guide: Expandable MenusIf you click on the 'WebBuilder Sites' or 'Clipart Sites' their sub-menu is displayed. In this article I will discuss how to create this type of menus. The HTML code is given below:
As you can see the whole code is placed within an unordered list. There are two list items: 'WebBuilder Sites'(line 2) & 'Clipart Sites'(line 7). Within each of the list item there is a paragraph. The first paragraph starts at line 3 and ends at 6. The id of it is 'listOne'. These paragraphs have been made invisible using style parameters 'display:none'(line 3 & 8). Now let us look at the list items in detail. The list items(line 2 & 7) are wrapped in an anchor tag. The URL of the anchor tags are javascript:expandIt(document.getElementById('listOne')) & javascript:expandIt(document.getElementById('listTwo')) respectively. Thus clicking on these items actually call the JavaScript function expandIt(). The first list item passes the argument listOne Element and the second one listTwo Element (from the DOM tree) to the said function. So isn't it time that we looked at this JavaScript function?
When the user clicks on the 'WebBuilder Sites' the function expandIt() is triggered. The argument passed is 'listOne', the id of the invisible paragraph. This fact is stored in the variable 'getIt'. Now comes the action part. The line 4 of the program checks whether the layer(paragraph) with id 'listOne' is visible or not. If it is not visible, then the function makes it visible or vice versa. For optimized code we have used the ternary operator instead of the if..else structure. The syntax of ternary operator is: |
[Quick Stats: Number of main threads: 12, Number of sub-threads: 4]
Sign Guestbook
|
Who is Subhash?
The contents of this site are copyright© 2000-2008, indiWiz.com. All Rights Reserved.