我有以下html结构。
<html>
<head></head>
<body class="primary-define color-custom">
<div id="header"></div>
<div id="container">
<div id="container-inner" class="wrapper clearafter">
<div id="notification" class="active">.. notification content here</div>
<div id="content">content here</div>
</div>
</div>
</body>
</html>
如何使用jQuery将通知移出容器和标题,如下所示?
<html>
<head></head>
<body class="primary-define color-custom">
<div id="notification" class="active">.. notification content here</div>
<div id="header"></div>
<div id="container">
<div id="container-inner" class="wrapper clearafter">
<div id="content">content here</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:2)
<强> HTML 强>
<html>
<head></head>
<body class="primary-define color-custom">
<div id="header"></div>
<div id="container">
<div id="container-inner" class="wrapper clearafter">
<div id="notification" class="active">.. notification content here</div>
<div id="content">content here</div>
</div>
</div>
</body>
</html>
<强> JS 强>
$(function(){
var a = $("#notification");
$("body").prepend(a);
});
答案 1 :(得分:0)
$('#notification').insertBefore($('#header'))
<强> jsFiddle example 强>
结果:
<body class="primary-define color-custom">
<div id="notification" class="active">.. notification content here</div>
<div id="header"></div>
<div id="container">
<div id="container-inner" class="wrapper clearafter">
<div id="content">content here</div>
</div>
</div>
</body>