title: jquery: set image width but no larger than original size?
body: <p>hey guys,
  i wonder how to solve this:</p>
  
  <pre><code>function setimgwidth() {
      var bw = $('.post-body').width();
      $(".post-body p img").each(function() {
          var os = $(this).width();
          //if (bw &lt; os) {
              $(this).removeAttr('height');
              $(this).width(bw);
          //}
      });
  }
  </code></pre>
  
  <p>basically my .post-body div is dynamically asdjusted to the screensize.
  every image inside of it should as well be resized to the width of the .post-body div, but only if the .post-body is NOT larger than the original size of the image. i don't want the image to get blurry.</p>
  
  <p>as for now it actually works almost like i want it to. the function is called on window resize. however if the .post-body is larger than the actual image-size the image gets still enlarged. </p>
  
  <p>if I uncomment the code above it seems to work, but only if i resize the window to a smaller size. if it's resized larger the image will not adjust anymore and stay small.
  that's probably because the original size gets overwritten every time i call the function.</p>
  
  <p>somehow i can't find a proper solution and i need your help, please.
  thank you in advance,
  matt</p>