I am facing a problem with DIV clicks using JQuery. Need advise on this issue.
I have three DIV elements in my html as follows,
<html>
<body>
<div id="overviewContainer">
<div id="firstContainer"></div>
<div id="secondContainer"></div>
</div>
</body>
</html>
My requirement is,
1)When I click on firstContainer, the secondContainer must disappear and my firstContainer should expand and occupy the space of the secondContainer.
2)When I again click on firstContainer, the secondContainer must appear and my firstContainer should shrink to the original position and leave space for secondContainer.
For this, I have written the following jQuery code
$(function() {
var firstContainerMaximized = false;
alert("Jquery invoked");
$('#firstContainer').click(function(e) {
//var firstContainerMaximized = firstContainerMaximized;
alert("fist container clicked");
if( firstContainerMaximized == false ) {
alert("maximizing clicked");
firstContainerMaximized = true;
$('#secondContainer').hide(); //hide the 2nd container.
$(this).css({ //modify the 1st container
"right":"1%"
});
} else if( firstContainerMaximized == true ) {
alert("minimizing clicked");
firstContainerMaximized == false;
$('#secondContainer').show(); //show the 2nd container.
$(this).css({ //modify the 1st container
"right":"49%"
});
}
});
$('#secondContainer').click(function(e) {
alert("second container clicked");
});
});
The logic works for first 2 clicks. That is, when I first click my firstContainer, the variable firstContainerMaximized was set to FALSE and my firstContainer expands as expected.
When I click on firstContainer 2nd time, the variable firstContainerMaximized was set to TRUE and my firstContainer shrinks as expected.
But when I click on firstContainer from 3rd time onwards, the variable firstContainerMaximized always set to TRUE. It is not expanding again as expected.
Kindly advise where I am going wrong here?
Is there any alternative design available to meet my requirement??