PatrickH
PatrickH

Reputation: 39

jQuery calculation gives NaN

Im trying to do a calculation, but i constantly get the error NaN; Could you help me out how to do the math for var testBottom?

jQuery(document).ready(function(){
var test = jQuery("#test");
var testTopOffset = test.offset();
var testTop = testTopOffset;
var testHeight = test.height();
var testBottom = parseInt(testTop + testHeight);
alert(testHeight);
alert(testBottom);
});

Upvotes: 0

Views: 196

Answers (2)

Luca Rainone
Luca Rainone

Reputation: 16458

var testTopOffset = test.offset();

should be

var testTopOffset = test.offset().top

Upvotes: 1

jbabey
jbabey

Reputation: 46647

test.offset(); returns an object with top and left properties, not a number. if you want the top offset you need to drill down:

var testTopOffset = test.offset().top;

See the documentation.

Upvotes: 3

Related Questions