javascript display menu stall on first onclick

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

javascript display menu stall on first onclick

Post by kendall »

Hello,

the following is a script that checks a div tag for its display attribute and sets it the opposite

function menu(id)
{
temp_Obj = attach(id);
element = temp_Obj.style.display;
if(element == 'none'){
temp_Obj.style.display = 'inline';
}else{
temp_Obj.style.display = 'none';
}
}

but on the first onClick = menu('submenu') it doesnt do any thing(divs are set to done by default css)
however on a second attempt it will

Whats wrong?

Kendall
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

set the style tag in the div when you write/output the code, otherwise it first has to set up the style before it can changes, which is probably why when you clikc it the first time nothing happens but if you click it again it works.
Post Reply