我想要在添加最后一个元素之后获取div高度,而不使用css溢出。如何在添加jquery后添加div高度而不使用css溢出
HTML代码:
<div id="wall"></div>
Javacript代码:
var walldown = setInterval(walldownfn, 10000);
function walldownfn() {
$.post("/php/post.php", function(data, status){
$("#wall").append(data+"<br>");
});
var awrap = document.getElementById("wall");
alert(awrap);
}
报警输出:
[object HTMLDivElement] or 0 height
Ajax响应数据是HTML代码。
例子:
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="..." alt="Card image cap">
<div class="card-block">
<h4 class="card-title">Card title</h4>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
你试过'$(“#wall”)。height()'? – HtmHell
是的,但是也总是得到0高度 – ind
你需要在函数内部追加内容后调用它。 – HtmHell