title: Add class to divs which contains an image of a certain width
body: <p>Hi let me start with the codes.</p>
  
  <pre><code>&lt;div class="nyhet"&gt; &lt;img src="#" width="785" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="390" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="785" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="390" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="785" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="390" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="785" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet"&gt; &lt;img src="#" width="390" class="attachement-full" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Ok, so basically what I want is that the divs with an image that is 785 should get a class named large added to it, and the divs with an image that is 390 should get a class named small.</p>
  
  <p>So it should look like this.</p>
  
  <pre><code>&lt;div class="nyhet large"&gt; &lt;img src="#" width="785" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet small"&gt; &lt;img src="#" width="390" class="attachement-full" /&gt;&lt;/div&gt;
  &lt;div class="nyhet large"&gt; &lt;img src="#" width="785" class="attachement-full" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>and so on.
  This is what I've tried to so far.</p>
  
  <pre><code>$(document).ready(function(){
    var x = $(".nyhet").length;
    for (var i=0; i&lt;x;i++){
      n = $(".attachement-full:eq(i)").attr("width");
      if (n&lt;785) {
        $(".nyhet:eq(i)").addClass("small");
      } else {
        $(".nyhet:eq(i)").addClass("large");
      }
    }
  });
  </code></pre>
  
  <p>I chose to use .attr instead of .width because the images probably won't be finished loading  when the script runs.</p>
  
  <p>Any help would be appriciated!</p>