Jump to content

Problem with javascript expand collapse function, help!


Liquid Fire

Recommended Posts

Here is my code for the expand collapse i have come up with, it pretty simple:
[code]
function ExpandCollapse(passed_id)
{
var element=document.getElementById(passed_id);

if(!element)
{
return false;
}

if(element.style.display=="none")
{
element.style.display="block"
}
else
{
element.style.display="none"
}

return false;
}[/code]

this works fine when the div is already set to "display: block" but when i the div is first set to "display:none" i need to click on the link 2 time for it to start to work, the first click does nothing, anyone know why?

on a side note does returning true is javascript reload the page or something because when i first built this i have it as return true and that would collapse the menu but then right after reload the page with the menu at is default value?
Could be that your browser's security settings disable javascript components until you have clicked it once.  Many times IE is set-up this way. 

Could also be that javascript is including the white space in "display: none"  and actually sets the style property to " none" instead of "none".  Try modifying your CSS file to reflect "display:none"  or have javascirt match " none".

Those are the only two things I can think of.
check out YUI at [url=http://developer.yahoo.com/yui]developer.yahoo.com/yui[/url]

They have awesome tools that are cross browser and easy to use.  When ever I need javascript functionality I use that library.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.