我试图通过从另一个div
获取height
来更改div
的height
,但我得到了错误Cannot set property 'height' of undefined
。
代码:
$("#loading_image_container").style.height = $('#content_frame').height();
我确信content_frame的高度是500px。
尝试
$("#loading_image_container").height($('#content_frame').height());
因为您引用的是jQuery对象,而不是DOM元素。使用内置的jQuery函数如下:
$("#loading_image_container").height($('#content_frame').height());
或者,首先获取DOM元素:
$("#loading_image_container")[0].style.height = $('#content_frame').height();
您正试图设置jQuery对象的style
,请使用CSS
$("#loading_image_container").css("height", $('#content_frame').height());
或者:
$("#loading_image_container")[0].style.height = $('#content_frame').height();
试试这个:
$(".div1").css({'height':($(".div2").height()+'px')});
也许您错过了正确表达式中的.style:尝试
$("#loading_image_container").style.height = $('#content_frame').style.height;