DaveLinger Posted January 27, 2007 Share Posted January 27, 2007 Here's the code "in action":http://www.dragonforceusa.comjust click "There are x comments for this post", and it will toggle the style of "commentsx" from "show:none" (in-line) to "show:block". Problem is, it doesn't toggle back when I click the link again, and it should. Here is the javascript:[code]function toggleLayer(whichLayer){if (document.getElementById){// this is the way the standards workvar style2 = document.getElementById(whichLayer).style;style2.display = style2.display? "":"block";}else if (document.all){// this is the way old msie versions workvar style2 = document.all[whichLayer].style;style2.display = style2.display? "":"block";}else if (document.layers){// this is the way nn4 worksvar style2 = document.layers[whichLayer].style;style2.display = style2.display? "":"block";}}[/code] Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted January 27, 2007 Author Share Posted January 27, 2007 also here's where i found the code (with the example that toggles):http://www.netlobo.com/div_hiding.htmlOH CRAP, I just noticed that the whole page is blank in IE! Please help!http://www.dragonforceusa.com/ Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted January 28, 2007 Author Share Posted January 28, 2007 Update: just found out that it is the javascript file that is causing this to crash, here's the code:[code]function toggleLayer(whichLayer){if (document.getElementById){// this is the way the standards workvar style2 = document.getElementById(whichLayer).style;style2.display = style2.display? "":"block";}else if (document.all){// this is the way old msie versions workvar style2 = document.all[whichLayer].style;style2.display = style2.display? "":"block";}else if (document.layers){// this is the way nn4 worksvar style2 = document.layers[whichLayer].style;style2.display = style2.display? "":"block";}}[/code] Quote Link to comment Share on other sites More sharing options...
mainewoods Posted January 28, 2007 Share Posted January 28, 2007 This way works in both ff and ie:[code]object.style.display = 'none'; // disappearsobject.style.display = ''; // displays in default format for item[/code] Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted January 28, 2007 Author Share Posted January 28, 2007 Hm...Sorry for being a total Javascript noob, but how would I go about implementing that code? It doesn't specify which object it's hiding. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted January 28, 2007 Share Posted January 28, 2007 use with your 'whichLayer' (I assume you are passing the item id in 'whichlayer')[code]// makes element disappeardocument.getElementById('whichLayer').style.display = 'none';// makes element display in default format for element document.getElementById('whichLayer').style.display = ''; [/code] Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted January 28, 2007 Author Share Posted January 28, 2007 gah, I'm sorry but I can't get it to work... here's the code in my .js file:[code]function toggleLayer(whichLayer){// makes element display in default format for element document.getElementById('whichLayer').style.display = 'block';// makes element disappeardocument.getElementById('whichLayer').style.display = 'none';}[/code]I switched the order and changed the "appear" code to "block" instead of default, because default is "none". It starts hidden. An example link is "javascript:toggleLayer('comments6');", with comments6 being a div with style display:none Quote Link to comment Share on other sites More sharing options...
mainewoods Posted January 28, 2007 Share Posted January 28, 2007 [code]function toggleLayer(whichLayer){// makes element display in default format for element if (document.getElementById('whichLayer').style.display == 'none') document.getElementById('whichLayer').style.display = 'block';// makes element disappearif (document.getElementById('whichLayer').style.display == 'block') document.getElementById('whichLayer').style.display = 'none';}[/code] Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted January 28, 2007 Author Share Posted January 28, 2007 [quote author=mainewoods link=topic=124258.msg515669#msg515669 date=1170018103][code]function toggleLayer(whichLayer){// makes element display in default format for element if (document.getElementById('whichLayer').style.display == 'none') document.getElementById('whichLayer').style.display = 'block';// makes element disappearif (document.getElementById('whichLayer').style.display == 'block') document.getElementById('whichLayer').style.display = 'none';}[/code][/quote]still not working, here's the url of the code in action:http://www.dragonforceusa.com/Thanks for your help so far. Quote Link to comment Share on other sites More sharing options...
Zeon Posted January 29, 2007 Share Posted January 29, 2007 remove the quotes around [i]whichLayer[/i]:[code]document.getElementById(whichLayer)[/code] Quote Link to comment Share on other sites More sharing options...
DaveLinger Posted January 29, 2007 Author Share Posted January 29, 2007 still nothing =/ Quote Link to comment Share on other sites More sharing options...
makeshift_theory Posted January 29, 2007 Share Posted January 29, 2007 Try this[code]function toggle(id){var layer = document.getElementById(id);if(layer.style.display == 'none')layer.style.display = 'block';elselayer.style.display = 'none';}<a href="javascript: toggle('throughfireandflames')">Test</a><div id="throughfireandflames' name='throughfireandflames' style="display:none;">Test</div>[/code]PS> Dragonforce is a awesome band =). 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.