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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.