0

How can i find if image has no height style property.

Css in Html

<img id="image" src="images/sports/sports9.png" style="width:100px">

Jquery

 if($('#image').css('height') == 0)
    {
        var imageWidth = $("#image").width();
        $("#image").css("width",""+(imageWidth-1)+"px");
    }

2 Answers2

2

Try this:

var img = document.getElementById('image');
if( !img.style.height) img.style.width = img.width-1+"px";
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Sometimes people forget regular javascript still exists. (I'm guilty of this as well) – Andy Feb 06 '13 at 10:18
0

Perhaps this is what you are after?

http://binodsuman.blogspot.se/2009/06/how-to-get-height-and-widht-of-image.html

Or do you mean that you would like to check if the image has a height property set or not?

Update:

Check here for a similar question

jQuery check if element has a specific style property defined inline

Community
  • 1
  • 1
inquam
  • 12,664
  • 15
  • 61
  • 101