javascript function for multiple actions -


if using js code:

<script language="javascript" type="text/javascript">      function showhidediv()     {         var divstyle = new string();         divstyle = document.getelementbyid("elementid").style.visibility;         if(divstyle.tolowercase()=="visible" || divstyle == "")         {             document.getelementbyid("elementid").style.visibility = "hidden";         }         else         {             document.getelementbyid("elementid").style.visibility = "visible";         }     } </script> 

and html:

<a href="#" class="action" id="action" onclick="return showhidediv();">menu</a>     <div id="elementid" style="visibility:hidden">      content here      </div> 

what best way have div link expands div not have multiple functions it?

just add function argument:

function showhidediv(id) {     var element = document.getelementbyid(id),     visibility = element.style.visibility.tolowercase(),     isvisible = visibility === "visible" || visibility === "";      element.style.visibility = isvisible ? 'hidden' : 'visible'; } 

then in html, pass this:

onclick="showhidediv('elementid');" 

demo


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -