I have a small control panel which contains three divs(title, content, and a dummy div). Above that panel i have a button which when clicked has to hide and show the content.
My aim is when i click the button to change the content div's id when it is hidden and when it is shown, also the button has to change from Close to Open. At this stage i make the content appear and dissapear but it is bugged. I think i have to use stopPropegation but i dont know how. If you can fix it i would be greatfull. Thanks in advance.
html code:
<!DOCTYPE html>
<html>
<head>
<title>Control Panel</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="collapseExpand.js"></script>
</head>
<body>
<div id="button">
<a href="javascript:void(0);" onclick="return hideShowContent()">Close</a>
</div>
<div class="wrapper">
<h1>Title</h1>
<div id="content"> "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>
</div>
<div id="dummyDiv">
test division
</div>
</body>
</html>
css code:
html, body {
height: 100%;
}
html {
display: table;
margin: auto;
}
body {
display: table-cell;
vertical-align: middle;
}
#button{
margin-bottom: 10px;
}
h1{
margin-left: 10px;
margin-right: 10px;
border-bottom: 1px solid gray;
}
.wrapper{
border: 1px solid gray;
width: 430px;
}
#content, #contentHide{
margin: 10px;
}
#dummyDiv{
margin-top: 10px;
font-weight: bold;
font-size: 1.2em;
}
JavaScript code:
function hideShowContent() {
console.log('The button was clicked');
$(document).ready(function() {
$('#button').click(function() {
$("#content").attr('id', 'contentHide');
$('#contentHide').hide(500);
});
});
$(document).ready(function() {
$('#button').click(function() {
$("#contentHide").attr('id', 'content');
$('#content').show(500);
});
});
}
JSfiddle: http://jsfiddle.net/wvLfbfgh/