On my Tumblr Theme I want to use a different CSS class for portrait images.
Images, by default, come in via img
-tag and get's the class bilder
. But if it's an portrait image, I would like to replace the builder
class with the hhcoch
class.
HTML:
<img src="{..}" />
JavaScript:
var someImg = $("img");
if (someImg.height() > someImg.width()){
$( "img" ).addClass( "hhoch" );
}
CSS:
.bilder {
height: auto; /*override the width below*/
min-width: 100%;
max-width: 100%;
display: inline;
text-align: center;
margin-left: auto;
margin-right: auto;
}
.hhoch {
min-height: 800px;
max-height: 800px;
width: auto;
}
Sum up: The image should get a different class if it's portrait.
You've got the right idea, however that specific jQuery selector you're using is going to return an array of ALL the image tags in your document.
This means you'll want to loop over the array of image DOM nodes and apply your class that way.