Jump to content

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.
My thought would be either using !="none" which would of course mean flipping the block and none, or maybe even just making a specific declaration in the CSS to begin with if you haven't tried that already.
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.