title: jQuery changing an image on hover, then maintain image on click
body: <p>I'm at a bit of a problem with jQuery and an image.</p>
  
  <p>I'm trying to create a simple system where an image changes on hover (which I've successfully made work with jQuery .hover()) however I'm now trying to set it up so if the user clicks on the image, the source is permanently changed to the hover image.</p>
  
  <p>The problem I'm having is when I click, the source changes but when I hover off it changes back to the "off" image! Such a simple problem but I can't find a solution.</p>
  
  <p>The hover code:</p>
  
  <pre><code>$("#image").hover(function () {
              $(this).attr("src", getImageSourceOn("image"));
          }, function () {
              $(this).attr("src", getImageSourceOff("image"));
  });
  </code></pre>
  
  <p>The functions getImageSourceOn / Off simply return a string based on the parameter with the new source.</p>
  
  <p>The onClick code:</p>
  
  <pre><code>var imageSource = $(imageID).attr("src");
    var onOff = imageSource.substring((imageSource.length - 5), (imageSource.length - 4));
    if (onOff == "F")
    {
      //alert("Off\nstrID = " + strID);
      $(imageID).attr("src", getImageSourceOn(strID));
    }
    else
    {
      //alert("On");
      $(imageID).attr("src", getImageSourceOff(strID));
    }
  </code></pre>
  
  <p>This code just takes the source and looks for On / Off within the source to put the opposite as the image. I tried using .toggle() instead of this substring method but I couldn't get it to work.</p>