Drop-down menu question

M

matt

Hi everyone,

I'm not really a developer but I've been trying to make a very simple
drop-down menu with JavaScript for a site I'm putting together.
Everything works fine on the page, but the Firefox developer's toolbar
I've got installed gives me this error:

"this.getElementsByTagName("ul")[0] has no properties"

Again, the menu works like it's supposed to, but this error is bugging
me. Here's the code:

function change() {
for (i=0; i<=10; i++) {
var sm=document.getElementById('submenu'+i)
if (sm)
{sm.style.display='none';}
}
for (i=0; i<=10; i++) {
var
dropmenu=document.getElementById('nav').getElementsByTagName('li');
dropmenu.onmouseover=function () {this.getElementsByTagName('ul')
[0].style.display='block';}
dropmenu.onmouseout=function () {this.getElementsByTagName('ul')
[0].style.display='none';}
}
}
window.onload=change;

And here's a link to the menus in action:

http://www.eagle1.american.edu/~wh9012a/menu/drop-down-menu.html

Any and all suggestions will be appreciated!
 
R

Rozzy

Hi everyone,

I'm not really a developer but I've been trying to make a very simple
drop-down menu with JavaScript for a site I'm putting together.
Everything works fine on the page, but the Firefox developer's toolbar
I've got installed gives me this error:

"this.getElementsByTagName("ul")[0] has no properties"

Again, the menu works like it's supposed to, but this error is bugging
me. Here's the code:

function change() {
for (i=0; i<=10; i++) {
var sm=document.getElementById('submenu'+i)
if (sm)
{sm.style.display='none';}
}
for (i=0; i<=10; i++) {
var
dropmenu=document.getElementById('nav').getElementsByTagName('li');
dropmenu.onmouseover=function () {this.getElementsByTagName('ul')
[0].style.display='block';}
dropmenu.onmouseout=function () {this.getElementsByTagName('ul')
[0].style.display='none';}
}}

window.onload=change;

And here's a link to the menus in action:

http://www.eagle1.american.edu/~wh9012a/menu/drop-down-menu.html

Any and all suggestions will be appreciated!


The problem is that you have li tags as children of li tags so when
you call getElementsByTagName your getting all the children of that
element with the tag name li, what you want to do is get the direct
descendants of the element like so:

dropmenu=document.getElementById('nav').childNodes;

you may have to run a while loop to escape all the text nodes if there
are any
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top