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');"
Comments
Post a Comment