Note that there are some explanatory texts on larger screens.

plurals
  1. POremove image if condition jquery
    primarykey
    data
    text
    <p>I load in a div with class name <strong>".preview"</strong> image's gallery like this:</p> <pre><code>&lt;img src="http://i2.cdn.turner.com/cnn/dam/assets/120226120954-mandela-paper-t1-main.jpg" alt="120226120954-mandela-paper-t1-main"&gt; &lt;img src="http://i2.cdn.turner.com/cnn/dam/assets/120226120954-mandela-paper-t1-main.jpg" alt="120226120954-mandela-paper-t1-main"&gt; &lt;img src="http://i.cdn.turner.com/cnn/.e/img/3.0/global/icons/video_icon.gif" alt="Video_icon"&gt; . . . </code></pre> <p>I have this function for remove img if exist a condition:</p> <pre><code> $('.preview').load(function(e){ img = $(this).find('img'); if((img.height() &lt; 50) || (img.width() &lt; 50)){ img.remove(); } }); </code></pre> <p><strong>My problem is that every images are removed</strong> </p> <p>I just want to remove from <strong>".preview"</strong> the images which have a <strong>width</strong> or <strong>height</strong> less than <strong>50px.</strong></p> <h3> Edited </h3> <p>I get in every images the value <strong>"0"</strong> for height in alert for this code, so delete every the images. But the images have not this value.</p> <pre><code>$('form#get_url_image').bind('ajax:success', function() { $('.preview img').load(function() { var $img = $(this); alert ($img.height()); if ($img.height() &lt; 50 || $img.width() &lt; 50) { $img.remove(); } }); }); </code></pre> <p>I get the images with each block:</p> <pre><code>&lt;div class="preview"&gt; &lt;% @images_urls.each do |image_url| %&gt; &lt;%= image_tag "#{image_url}" %&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload