Suppose I am implementing the following JS Code:
<script language="javascript" type="text/javascript">
function toggleVisibility() {
var element = document.getElementById("elementId");
if(element.style.visibility.toLowerCase()=="visible" || element.style.visibility == "") {
element.style.visibility = "hidden";
} else {
element.style.visibility = "visible";
}
}
</script>
and then using this HTML code:
<a href="#" class="Action" id="action" onclick="return toggleVisibility();">Toggle Menu</a>
<div id="elementId" style="visibility:hidden">
content here
</div>
What is the optimal way to add another div with a link that expands the same div without duplicating the function?