title: jQuery Toggle switch images
body: <p>I have a situation where I am not understanding jQuery's Toggle.</p>
  
  <p>I have two buttons, both of them open the same content and when you click on either button the  content should open or close and the attribute changes the button from open to closed. (So both buttons do the same function).</p>
  
  <p>Only thing is, when I click on the top button and it opens my content and then click on the lower button to close it, the image attributes are switched incorrectly.</p>
  
  <p>Here's a very stripped down version of what my code looks like and I would appreciate some help.</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
      $(function () {
  
          var open = false;
  
          $("#button1, #button2").toggle(
              function () {
                  open = true;
                  $("#button1").attr("src", "images/btn-open.gif");
                  $("#button2").attr("src", "images/btn-open.gif");
              },
              function () {
                  if (open) {
                      $("#button1").attr("src", "images/btn-closed.gif");
                      $("#button2").attr("src", "images/btn-closed.gif");
  
                  } else {
                      $("#button1").attr("src", "images/btn-open.gif");
                      $("#button2").attr("src", "images/btn-open.gif");
  
                  }
                  open = false;
  
              }
          );
  
  
      });
  &lt;/script&gt;
  
  &lt;img id="button1" src="images/btn-open.gif"&gt;&lt;/img&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;img id="button2" src="images/btn-open.gif"&gt;&lt;/img&gt;
  </code></pre>