未被捕获的HierarchyRequestError:无法在“节点”上执行“ insertBefore”:新的子元素包含父元素。
我只是尝试追加span9之前span3,当窗口宽度小于767,我有这样的错误,这是为什么?
$(document).ready(function() {
// Optimalisation: Store the references outside the event handler:
var $window = $(window);
var $content = $('.content');
var $cats = $('.span3');
function checkWidth() {
var windowsize = $window.width();
if (windowsize < 767) {
$content.insertBefore($cats);
} else if (windowsize > 767) {
$content.insertAfter($cats);
}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="content-entry">
<div class="row">
<div class="span3">span3</div>
<div class="span9 content">span9/content</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)