javascript - Trouble opening and closing a div with jQuery -
.box-one { border: 0.1em solid #ccc; } .dropdown-info { display: none; }
<div class="box-one"> <div class="header"> <h3 class="text-center">sample header</h3> </div> <div class="dropdown-info"> <p class="text-center">sample text</p> </div> </div>
i'm trying open , close div if div clicked on , tried both .toggle() , .click() won't work. else's opinion on it. show how tried accomplishing using both methods
$(document).ready(function() { var descriptionopen = false; if (descriptionopen === false) { $('.header').click(function() { $('.dropdown-info').show(); descriptionopen === true; }); }; else if (descriptionopen === true) { $('.header').click(function() { $('.dropdown-info').hide(); descriptionopen === false; }); }; }); $(document).ready(function() { $('.header').toggle(function() { ('.dropdown-info').show(); }, function() { ('.dropdown-info').hide(); }); });
just this:
$('.header').click(function() { $('.dropdown-info').toggle(); });
Comments
Post a Comment