I have the following Jquery to show and hide divs with a button click. It works fine only on the first two clicks. After the second click a hashtag appears in the URL and the script doesn't work. I tried putting e.preventDefault()
at the top of the method, but that prevents the click event from even working. What could possibly be wrong here?
<script>
$(document).ready(function () {
$('.container').hide();
$('.status-icon').text("+");
$('#expandsections').click(function (e) {
var allContentToggleContainers = $('.content-toggle .container');
var allVisibleContentToggleContainers = allContentToggleContainers.filter(function () {
return $(this).css("display") == "block";
});
if (allContentToggleContainers.length && allContentToggleContainers.length === allVisibleContentToggleContainers.length) {
allContentToggleContainers.hide().next().slideUp();
$('.status-icon').text("+");
}
else {
allContentToggles.not('selector:visible').show().next().slideDown();
$('.status-icon').text("+");
}
return false;
});
});
</script>