【发布时间】:2011-01-12 02:33:00
【问题描述】:
我克隆了一个 DIV 并可以更改它的 CSS 属性,但找不到如何更改它的子 DIV 的 CSS。 在下面的示例中,我想将 #details-child 的背景从黄色更改为蓝色。 CSS:
#wrapper {
width:200px;
background:gray;
}
#details {
width:200px;
height:100px;
background:green;
}
#details-child {
width:100px;
height:100px;
background:yellow;
}
JS:
jQuery.noConflict();
jQuery(document).ready(function() {
// clone
clone_details = jQuery("#details").clone();
// change CSS
clone_details.css({'margin-top':'50px', 'background':'red'});
// jQuery("#details-child").css('background','blue'); // changes original div
// render clone
jQuery("#wrapper").append(clone_details);
});
【问题讨论】: