简体   繁体   中英

jQuery .height() property not working

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.compatMode === "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!

var contentheight = $('#subpage-content-small').height();

这是一种功能,而不是财产。

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 recommended when an element's height needs to be used in a mathematical calculation.

Try calling it as height() instead of height

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM