jQuery选择器在添加到DOM之前编辑HTML

Mik*_*ell 3 jquery

我试图使用jQuery选择器向DOM添加一些内容,但我想在添加之前对其进行操作.

var $content = $('<h1>title</h1><h2 id="xx">remove me</h2><p>some content or other</p>');

$content.remove('#xx');

$('#output').append($content);
Run Code Online (Sandbox Code Playgroud)

我把它放在jsfiddle这里http://jsfiddle.net/NNcG5/1/

非常感谢,迈克

Mar*_*tin 5

我推荐 $content.not('#xx').appendTo('#output');

我还与解决方案更新您的JS小提琴也是如此,在这里.