I'm having a bit of trouble with jquery looping through a set of html code. I wrote a wee conditional script that detects if an image if portrait or landscape and adds a class for either. This worked great in isolation but now I need to to detect multiple instances on the same page...
<li>
<figure class="eventimage">
<img class="" src="images/home1.jpg">
</figure>
<div>
some other code that is not important
</div>
</li>
<li>
<figure class="eventimage">
<img class="" src="images/home2.jpg">
</figure>
<div>
some other code that is not important
</div>
</li>
<li>
<figure class="eventimage">
<img class="" src="images/home3.jpg">
</figure>
<div>
some other code that is not important
</div>
</li>
<li>
<figure class="eventimage">
<img class="" src="images/home4.jpg">
</figure>
<div>
some other code that is not important
</div>
</li>
So I thought it take advantage of the .each method...
$(".eventimage img").each(function() {
if ( .width() > .height()){
//it's a landscape
$(this).addClass("landscape");
} else if ( .width() < .height()){
//it's a portrait
$(this).addClass("portrait");
} else {
$(this).addClass("canttell");
}
});
My problem is each img tag is outputting the exact same result and my test images are a good mixture of landscape and portrait so something isn't right.
Can anybody help?