0
我需要在保留子節點的同時明確地分離父節點。jquery:detach()父母不影響兒童... unwrap()確實太多了
unwrap()對我來說可以很好地工作,但是它會刪除div,我希望稍後恢復它。是否有分離的unwrap()方法?
舉例: CSS:
body{
background: green;
}
#parent{
height: 500px;
width: 500px;
background: black;
}
#red{
height: 250px;
width: 250px;
background: red;
float: left;
margin-top: 100px;
}
HTML
<body>
<div id="parent">
<div id="yellow">yellow</div>
<div id="red">red</div>
</div>
</body>
jQuery的
$(document).ready(function() {
$("#yellow").click(function(){
one();
});
$("#red").click(function(){
two();
});
});
function one(){
$("#yellow").unwrap();
}
function two(){
$("#parent").appendTo("body");
$("#yellow").appendTo("#parent");
$("#red").appendTo("#parent");
}
建議?