在div上设置width属性?

时间:2013-11-21 14:03:42

标签: javascript html css

我的DivTest和IdOtherDIV宽度相同。 我正在尝试这样设置属性:

DivTest {
background: #007C52;
width: document.getElementById ("IdOtherDIV").scrollWidth + "px.\n";
}

有没有办法实现它(IdOtherDIV是动态创建的,宽度可以在每次页面刷新时改变)?

1 个答案:

答案 0 :(得分:0)

您可以使用jquery

width=$("IdOtherDiv").css("width");
$("#DivTest").css({"background":"007C52","width":width})