在要更换的元件上取高度

take on height on element to be replaced

本文关键字:取高度      更新时间:2024-05-03

我将用.replaceWith()替换与类匹配的元素,如下所示:$('.dataCard').not('.focused').replaceWith('<div class="spaceHolder"></div>');;然而,我希望每个.spaceHolder在替换它们之前都具有它们所替换的.dataCard的高度。

我该怎么做?

$('.dataCard').not('.focused').each(function() {
    var div = $('<div />', {
        css : {height : $(this).height()}
    });
    $(this).replaceWith(div);
});