Minor tweak to this javascript function? -


i have script shows/hides used via onclick. can show/hide fine, can't show/'hide else'. bunch of open containers when want one.

javascript:

<script>     function showfields(fields){         if(document.getelementbyid(fields).style.display=='none'){             document.getelementbyid(fields).style.display='block';         }         else{             document.getelementbyid(fields).style.display = 'none';         }     } </script> 

html:

<div id="hidden" class="steps" style="display: block;">     <div class="section" style="margin-right: 10px;">         <h2>something</h2>     </div>     <button class="continue dropdown" id="showlink" onclick="showfields('hidden2');return false;" href="#">continue</button> </div> <div id="hidden2" class="steps" style="display: block;">     <div class="section" style="margin-right: 10px;">         <h2>something2</h2>     </div>     <button class="continue dropdown" id="showlink" onclick="showfields('hidden3');return false;" href="#">continue</button> </div> <div id="hidden3" class="steps" style="display: block;">     <div class="section" style="margin-right: 10px;">         <h2>something3</h2>     </div>     <button class="continue dropdown" id="showlink" onclick="showfields('hidden3');return false;" href="#">continue</button> </div> <div id="hidden4" class="steps" style="display: block;">     <div class="section" style="margin-right: 10px;">         <h2>something4</h2>     </div>     <button class="continue dropdown" id="showlink" onclick="showfields('hidden4');return false;" href="#">continue</button> </div> 

thanks

since you've tagged jquery assume option:

function showfields(fields){   $('.steps').hide()   $('#' + fields).show(); } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -