[英]How do you get div height in pure javascript?
什么是纯 javascript 中下面代码的等价物?
$('.div1').height($('.div2').height());
这将是以下内容:
document.querySelector(".div1").style.height = window.getComputedStyle(document.querySelector(".div2")).height;
Using document.getElementsByClassName
使用
document.getElementsByClassName
var height = document.getElementsByClassName("div1")[0].style.height;
document.getElementsByClassName("div2")[0].style.height = height;
Loop through all the elements with the class name, setting them all to the desired height.循环遍历所有具有类名的元素,将它们全部设置为所需的高度。 Like this:
像这样:
var div1s = document.getElementsByClassName(".div1");
var height = document.getElementsByClassName(".div2")[0].height;
for (int i = 0; i < div1s.length; i++) {
div1s[i].height = height;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.