close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<style type="text/css">
#box{
width: 100px;
height: 100px;
background-color: #fb0;
margin: 10px 0;
}
</style>
</head>
<body>
<div id="box"></div>
<button id="btn">刪掉</button>
<button id="btn2">復原</button>
<script type="text/javascript">
var x;
$('#btn').on('click',function(){
x = $('#box').detach();
});
$('#btn2').on('click',function(){
$('#btn').before(x);
});
</script>
</body>
</html>
全站熱搜