I am using a jQuery script to add a class (portrait or landscape) depending on their dimensions. Then I am using jQuery to center the image vertically. The script works perfectly when I past it into the console, but not when I link it in the document head. Here is the code I have:
jQuery( document ).ready(
function() {
jQuery(".imgResize").each( function () {
var $this = jQuery(this);
if ( $this.width() > $this.height() ) {
$this.addClass("landscape");
} else if ( $this.width() < $this.height() ) {
$this.addClass("portrait");
} else {
}
var $h = $this.height();
$this.css('margin-top', + $h / -2 + "px");
});
});
What would cause this issue?