I have the following HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<script language='javascript'>
window.onload = function () {
alert($('#object1').height());
};
</script>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
</head>
<body>
<object id="object1" height="205" width="246">
<img id="Img1" height="205" width="246" src="../images/google_ad_example.jpg" />
</object>
</body>
</html>
using jquery:
alert($('#object1').height());
I’m getting 19 back! and not 205 Why?
Thanks.
Hiya demo http://jsfiddle.net/keXRf/3/ (using
attr) or you can always set the css like here and use.csshttp://jsfiddle.net/LAp2c/link: http://api.jquery.com/height/ 🙂
Note: since attributes
height=is used in your case; you can useattrand that will give you desired output, but the link should help you to understand better.also extra info: you can assign
.css("height", 205)for consistancy across bwoser, there is a good discussion in the link I shared above.further: The difference between
.css('height')and.height()is that the latter returns a unit-less pixel value (for example,400) while the former returns a value with units intact (for example,400px). The.height()method is recommended when an element’s height needs to be used in a mathematical calculation.screenshot 1: in osx safari
screenshot 2: