Is there a way to achieve the following using pure JavaScript instead of jQuery?
I want to find the height of an image within a figure element and if the image's height is less than 200 pixels, I need to set its container's (parent's) height to auto.
The jQuery code provided works as expected, but I am interested in accomplishing this using plain JavaScript.
Check out the fiddle here.
HTML
<figure>
<img class="imgH" height="500" width="500" src="/some_img.jpg"/>
</figure>
<figure>
<img class="imgH" height="500" width="500" src="/some_img.jpg"/>
</figure>
<figure>
<img class="imgH" height="500" width="500" src="/some_img.jpg"/>
</figure>
<figure>
<img class="imgH" height="250" width="250" src="/some_img.jpg"/> // This image height is less than 300 pixels.
</figure>
<figure>
<img class="imgH" height="500" width="500" src="/some_img.jpg"/>
</figure>
CSS
figure {
width: 500px;
height: 500px;
}
JavaScript (jQuery)
$(document).ready(function(){
$(".imgH").each(function(){
if( $(this).height() < 200 ) {
$(this).parent().height( "auto" );
}
});
});