Liquid Fire Posted December 23, 2006 Share Posted December 23, 2006 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? Quote Link to comment Share on other sites More sharing options...
dustinnoe Posted December 23, 2006 Share Posted December 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted December 23, 2006 Share Posted December 23, 2006 just change it to if(ele.style.display != 'block')... Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted December 23, 2006 Author Share Posted December 23, 2006 if i change to != 'block, then the divs that are default to expand need to be clicked twice. it is"none, not " none", I have firefox 2.0 and javascript is fully enabled. any other thoughts Quote Link to comment Share on other sites More sharing options...
dustinnoe Posted December 23, 2006 Share Posted December 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted December 23, 2006 Author Share Posted December 23, 2006 I'd rather try to fix this, what shoudl be, simple function. Quote Link to comment Share on other sites More sharing options...
Telemachus Posted December 24, 2006 Share Posted December 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.