Here is my HTML and javascript code:
HTML:
<div id="common">
Hi Welcome
</div>
<div>
<a href="javascript:toggleDiv('customize');" >click here</a>
</div>
<div id="customize">
<form action="" method="post" id="MyForm">
{% form%}
</form>
</div>
Javascript code:
<script>
function toggleDiv(divId) {
if ($("#"+divId).show()) {
$("#common").hide();
}
else {
$("#common").show();
}
}
</script>
If i click the link “Click here” one div id should be hide and another should be show and if i click it another time vice-versa process should be happened. i tried using this javascript but it’s not worked properly
You need to use
:visibleto check if the passed div is already visible. Try this:You should also change your code to use jQuery to attach you events instead of the clunky
onclickattribute: