javascript - Hiding div on button click -


i have script has 3 buttons shows div when clicked, question how hide div's let's div 1 opened , click open div 2, make show div 2 hide div 1 can have div's in same position, show if supposed to.

my script:

  <!-- support contact form start-->             <div class="contactsupportbutton"><input type="button" src=".png" alt="contact support button" style="height: 40px; width: 120px" onclick="showsupform()"/>                     <div id="contactsupportform">                         test                     </div>                 </div>              <script type="text/javascript">                 function showsupform() {                 document.getelementbyid('contactsupportform').style.display = "block";                 }             </script>             <!-- support contact form ending-->              <!-- business contact form start-->             <div class="contactbusinessbutton"><input type="button" src=".png" alt="contact business button" style="height: 40px; width: 120px" onclick="showbusform()"/>                     <div id="contactbusinessform">                          test                     </div>                 </div>              <script type="text/javascript">                 function showbusform() {                 document.getelementbyid('contactbusinessform').style.display = "block";                 }             </script>             <!-- business contact form ending-->              <!-- other contact form start-->             <div class="contactotherbutton"><input type="button" src=".png" alt="contact other button" style="height: 40px; width: 120px" onclick="showotherform()"/>                     <div id="contactotherform">                         test                     </div>                 </div>              <script type="text/javascript">                 function showotherform() {                 document.getelementbyid('contactotherform').style.display = "block";                 }             </script>             <!-- other contact form ending--> 

css part:

#contactsupportform{     display: none; }  #contactbusinessform{     display: none; }  #contactotherform{     display: none; } 

here jsfiddle show whole process of how works. http://jsfiddle.net/m0jdv6u0/3/

you try this:

function showotherform(idelement) {     document.getelementbyid('contactotherform').style.display = "none";     document.getelementbyid('contactsupportform').style.display = "none";     document.getelementbyid('contactbusinessform').style.display = "none"     document.getelementbyid(idelement).style.display = "block" } 

and call in each button passing id of div, this:

showotherform('contactotherform') 

of course, can make verifications, don't need set display on 3 divs, think dont need that...

hope helped!


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -