dezkit Posted February 26, 2008 Share Posted February 26, 2008 how do i make more than one? <script type="text/javascript"> function change(ele) { element = document.getElementById(ele); (element.style.display == "block") ? element.style.display = "none" : element.style.display = "block"; }</script> <div onclick="change('below')"> This is some text. Click here to show more text. </div> <div id="below" style="display:none; "> This is some more text. You cannot see it on page load, click the text above to display it. </div> Link to comment https://forums.phpfreaks.com/topic/93046-help-w-javascript/ Share on other sites More sharing options...
rhodesa Posted February 26, 2008 Share Posted February 26, 2008 Another one like this? <script type="text/javascript"> function change(ele) { element = document.getElementById(ele); (element.style.display == "block") ? element.style.display = "none" : element.style.display = "block"; }</script> <div onclick="change('below')"> This is some text. Click here to show more text. </div> <div id="below" style="display:none; "> This is some more text. You cannot see it on page load, click the text above to display it. </div> <div onclick="change('another_one')"> This is some text. Click here to show more text. </div> <div id="another_one" style="display:none; "> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In commodo velit in nibh. Integer ultrices, diam vel feugiat porta, tellus libero accumsan elit, ac volutpat neque enim ut mi. Donec vel sapien. Nam interdum viverra mi. Cras purus felis, euismod eget, bibendum sed, auctor at, sapien. Duis non nibh. Suspendisse purus nulla, ultrices sit amet, fermentum iaculis, placerat rhoncus, augue. Integer nonummy ligula eget arcu. Pellentesque mauris. Curabitur accumsan magna quis eros. </div> Link to comment https://forums.phpfreaks.com/topic/93046-help-w-javascript/#findComment-476686 Share on other sites More sharing options...
fnairb Posted February 26, 2008 Share Posted February 26, 2008 Not really sure what you are going for but here are a few ideas... <script type="text/javascript"> var allDivs = array('id1', 'id2', 'id3'); // toggle only one at a time function showOnlyMe(ele) { for(var i = 0; i < allDivs.length; i++) { if (allDivs != ele && document.getElementById(allDivs).style.display != 'none') { document.getElementById(allDivs).style.display = 'none'; } else { document.getElementById(allDivs).style.display = 'block'; } } } // toggle all up to and including one function showUpToMe(ele) { // Until ele is found all divs will be displayed $setTo = 'block'; for(var i = 0; i < allDivs.length; i++) { document.getElementById(allDivs).style.display = $setTo; if (allDivs == ele) { // Once ele is found the rest will not be displayed $setTo = 'none'; } } } </script> Link to comment https://forums.phpfreaks.com/topic/93046-help-w-javascript/#findComment-476999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.