I would like to toggle a header div open and closed using jQuery's slideToggle() effect. I installed jquery-3.2.1.min.js and am using the following code:
$('.top-drawer').click(function() {
$('.top-drawer .myblock .container').slideToggle();
$('.top-drawer .closebutton').toggleClass('closed');
$('.top-drawer .openbutton').toggleClass('closed');
});
.myblock .container {
display: none;
height: 20%;
padding: 10pt 0;
overflow: hidden;
}
.openbutton.closed,
.closebutton.closed {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="top-drawer">
<div class="myblock">
<div class="container">
<div>
<h2>Hello World!</h2>
<p>
Lots of words....
</p>
</div>
</div>
</div>
<header class="closebutton closed">Close</header>
<header class="openbutton ">Open</header>
</section>
The toggleClass() function works just fine and if I replace slideToggle with toggleClass I can get the div to appear and disappear. But I don't get the slide effect. The error message is:
Uncaught TypeError: $(...).slideToggle is not a function
at HTMLElement.<anonymous> (mycode.js:134)
at HTMLElement.dispatch (jquery-3.2.1.min.js:3)
at HTMLElement.q.handle (jquery-3.2.1.min.js:3)
I've looked through other postings but was unable to see the problem. Originally I was using an older version of jQuery and thought that might be it. I first downloaded the new slim version but then discovered it didn't include effects. I then downloaded the min version but I am still getting an error.
Any help would be appreciated.