My functions are:
function init() {
var submenuHeads = document.
for (var i = 0; i submenuHeads[i].onclick = showMenu;
}
}
function hideAllMenuLists() {
var allMenuLists = document.quarySelectorAll("li.
for (var i = 0; i allMenuLists[i].style.display = "none";
}
}
function showMenu() {
var subIndex = parseInt(this.id);
var allMenus = document.
var currentMenu = document.getElementById(
var currentMenuList = currentMenu + ".ul[0]";
currentMenuList.style.display = "none"tion when the page is loaded by the browser.
8. Create the init() function. The purpose of this function is to add a dynamic id attribute to each pull-menu heading, and to create an on click event handler for each submenu heading. Add the following commands to the function:
a. Create the submenuHeads variable containing the object collection for all elements in the document belonging to the submenu had class.
b. Loop through the submenuHeads object collection, and for each item in the col-
lection do the following: i) add the id attribute i isubmenu_heading to the element, where i is the index number of the item in the object collection; and ii) run the showMenu() function when the item is clicked.
9. Create the hide all menu lists() function. The purpose of this function is to hide all pull-down menus on the page. Add the following commands to the function:
a. Create the all menu lists variable referencing all of the ul elements in the document that is nested within the li elements belonging to the submenu class.
(Hint: Use the querySelectorAll() method.)
b. Loop through the all menu lists object collection. For each item in the collection,
set the display style property value to none.
10. Create the showmen() function. The purpose of this function is to display the pull-
down menu corresponding to the menu heading that was clicked by the user. Add
the following commands to the function:
a. Create the subindex variable containing the index number found within the id property of the heading that was clicked by the user. (Hint: Use the parseInt()
function to extract the index number.)
b. Create the all menus variable containing the object collection of all elements belonging to the submenu class.
c. Create the current menu variable containing the element from the menus
object collection with the index number indicated by the subIndex variable.
d. Create the currentmenulist containing the first ul element nested within the
current menu object. This will be the pull-down menu that you will either hide or display on the page.
e. If the display property of currentMenuList is equal to block, change the display property to none to hide it; otherwise, because currentMenuList must be hidden,
run the hideAllMenuLists() function to hide all other pull-down menus on the page and change the display style property of currentMenuList to block.
I can send the steps and link my folder if you need
7. Go to the pullmenu.js file in your text editor. Insert a command to run the init() functions
Get Free Quote!
387 Experts Online