I am having an issue with my jQuery code. I have a button and a div element. The button should toggle the visibility of the div when clicked. I tried using a test to check the class of the div element. If the div is hidden, I want to make it visible, and if it's visible, I want to hide it. Here is the code I have, but I can't figure out what is wrong:
<button type="button" class="btn btn-default" id="btn-collapse">Left</button>
<div id="mapBlock" class="hidden"></div>
<script type="text/javascript">
$(document).ready(function() {
var classe = $('#mapBlock').attr('class');
$('#btn-collapse').click(function() {
if(classe == "hidden") {
$('#mapBlock').removeClass("hidden").addClass("visible");
}
if(classe == "visible") {
$('#mapBlock').removeClass("visible").addClass("hidden");
}
});
});
</script>