I have a container div with the follo开发者_Go百科wing CSS:
#container {
position:relative;
overflow:hidden;
width:200px;
height:200px;
}
Why does this:
alert('height is ' + $("#container").attr('height'));
Return that height is undefined?
Thanks.
You probably want to use the css or height methods.
$('#container').css('height')
or
$('#container').height();
depending on what you are trying to do with it. See the referenced documentation for the differences.
Try:
$("#container").height()
It is due to the height being in the css and not an actual attribute on the html tag.
jQuery.attr
refers to HTML attributes not CSS properties. Use .css("height")
or mentioned .height()
method.
More about those methods:
- jQuery.css()
- jQuery.attr()
- jQuery API Reference
精彩评论