I have a string:
var s = '<h1>heading</h1><p>para</p>';
and I want to remove the h1 element from it.
Ive tried:
$(s).remove('h1');
but s still contains the h1 element
Ive also tried:
s = $(s).remove('h1');
and
$('h1', s).remove();
and
$('h1', $(s)).remove();
etc etc etc
Any ideas?
Update: I see you just changed the question. Now the solution would be this:
Try it out: http://jsfiddle.net/q9crX/19/
Because you now have more than one “top level” element in the jQuery object, you can use
.not()(which is basically the opposite of.filter()) to remove theh1.It would be the same as doing
$(s).filter(':not(h1)');Original answer
So if you were to append the result to the
body, you could do:Try it out: http://jsfiddle.net/q9crX/