我克隆DIV后可以改变它的CSS属性,但是找不到如何更改它的子DIV的CSS. 在以下示例中,我想将#details-child的背景从黄色更改为蓝色. CSS: #wrapper { width:200px; background:gray;}#details { width:200px; h
在以下示例中,我想将#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);
});
一旦有了jquery对象,就可以使用$.find()在该对象的范围内进行选择器搜索.
http://api.jquery.com/find/
clone_details.find( ‘#细节儿’)的东西().
但是,您不希望到处都有重复的ID,因此我建议您转而使用类而不是ID,因为这些必须是唯一的.
