Reputation: 61
Im trying to run .outerHeight() function on element that i just appended to html via .append()
$("#someid").append("<ul id='#otherid'><li>something</li></ul>");
var h = $("#otherid").outerHeight();
After this "h" has wrong value. I think that it is caused by "append" not applying css to created elements. .outerHeight() runs correctly if i will put it in "setTimeout" but not right after "append".
Do you know how to get correct value of outerHeight after element was just appended?
Upvotes: 2
Views: 661
Reputation: 21
Instead: id='#otherid'
try: id='otherid'
$("#someid").append("<ul id='otherid'><li>something</li></ul>");
var h = $("#otherid").outerHeight();
Upvotes: 1
Reputation: 437
The reason for that is probably due to the fact that the appended elements do not have their CSS rules applied yet and are not counting towards the total height. Try using a delay (like settimeout) to make things work right.
var h = $("#otherid").delay(300).outerHeight();
Upvotes: 1