Slide up / Slide down when clicking same object - Help!

Slide up / Slide down when clicking same object - Help!

Hi! I am very new to using jquery (and any javascript at all really) and I am having a dillema. I am trying to have several expandable sections of my webpage but I only want one to be opened at a time so I want to use slideUp and slideDown rather than slideToggle.

I want to use the same button to open and close the section. How do I do this? Here is my current jquery code, as of right now when I click expandButton1 the itemContent1 section closes and then reopens immediately:


 <script>
    $("#expandButton1").click(function () {
    
      $("#itemContent1.opened").slideUp("slow").removeClass('opened').addClass('closed');
      
    });
    
    $("#expandButton1").click(function () {
      $("#itemContent1.closed").slideDown("slow").removeClass('closed').addClass('opened');
    });
</script>