admin管理员组文章数量:1297102
I'm attempting to get the height of an element using jQuery, but am receiving some unexpected results. Here's the code:
$(function() {
var contentheight = $('#subpage-content-small').height;
alert(contentheight);
});
Where #subpage-content-small has these CSS properties:
#subpage-content-small { width: 400px; float: left; margin: 30px 10px 0 0; padding-bottom: 45px; }
What I'm getting as an output for my alert is the following:
function (f) { var e = this[0]; if (!e) { return f == null ? null : this; } if (c.isFunction(f)) { return this.each(function (j) {var i = c(this);i[d](f.call(this, j, i[d]()));}); } return "scrollTo" in e && e.document ? e.documentpatMode === "CSS1Compat" && e.document.documentElement["client" + b] || e.document.body["client" + b] : e.nodeType === 9 ? Math.max(e.documentElement["client" + b], e.body["scroll" + b], e.documentElement["scroll" + b], e.body["offset" + b], e.documentElement["offset" + b]) : f === w ? c.css(e, d) : this.css(d, typeof f === "string" ? f : f + "px"); }
Any idea why I'm getting this as opposed to an integer of the height? Thanks in advance!
I'm attempting to get the height of an element using jQuery, but am receiving some unexpected results. Here's the code:
$(function() {
var contentheight = $('#subpage-content-small').height;
alert(contentheight);
});
Where #subpage-content-small has these CSS properties:
#subpage-content-small { width: 400px; float: left; margin: 30px 10px 0 0; padding-bottom: 45px; }
What I'm getting as an output for my alert is the following:
function (f) { var e = this[0]; if (!e) { return f == null ? null : this; } if (c.isFunction(f)) { return this.each(function (j) {var i = c(this);i[d](f.call(this, j, i[d]()));}); } return "scrollTo" in e && e.document ? e.document.patMode === "CSS1Compat" && e.document.documentElement["client" + b] || e.document.body["client" + b] : e.nodeType === 9 ? Math.max(e.documentElement["client" + b], e.body["scroll" + b], e.documentElement["scroll" + b], e.body["offset" + b], e.documentElement["offset" + b]) : f === w ? c.css(e, d) : this.css(d, typeof f === "string" ? f : f + "px"); }
Any idea why I'm getting this as opposed to an integer of the height? Thanks in advance!
Share Improve this question asked Apr 20, 2010 at 18:50 AndrewAndrew 1,8495 gold badges23 silver badges31 bronze badges2 Answers
Reset to default 8var contentheight = $('#subpage-content-small').height();
It's a function, not a property.
From jquery:
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 remended when an element's height needs to be used in a mathematical calculation.
Try calling it as height()
instead of height
本文标签: javascriptjQuery height() property not workingStack Overflow
版权声明:本文标题:javascript - jQuery .height() property not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741630415a2389329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论