I\'m trying to get the original width of an image with JQuery and make some adjustments in the CSS with a condition if an image is wider than 700px.
I used this code
your variable $imgWidth
is undeclared in your code, and imgWidth
will not have scope outside your function.
try:
var img = new Image();
img.src = $('#imageViewerImg').attr('src');
var imgWidth='';
img.onload = function() {
imgWidth = this.width;
}
if(imgWidth > 700) {
$("#photoHolder").css({"vertical-align":"none","text-align:":"none"});
}