After examining the jQuery source, I see that the problem I am facing is that replaceWith calls html , which does not exist for XML documents. Is replaceWith supposed to work with XML documents?
I found this admittedly a simple workaround, in case someone needs it in the future, this will accomplish what I'm trying to do:
xml.find('b').each(function() { $(this).replaceWith($('<c>yo</c>'))
But I would still like to know why the easy way doesn't work.
I don't know much about jQuery, but should this not work?
xml = $.parseXML('<a><b>hey</b></a>') $(xml).find('b').replaceWith('<c>yo</c>')
Instead of xml representing <a><c>yo</c></a> , it fails and represents <a></a> . Did I do something wrong? I am using jQuery 1.6.2.
Edit:
As a side note, if I try to use the version of the replaceWith function, like this:
$(xml).find('b').replaceWith(function() { return '<c>yo</c>'
I get this error:
TypeError: Cannot call method 'replace' of undefined
Edit 2:
replaceAll works, but I need to use the version of the function, so I cannot agree to this:
$('<c>yo</c>').replaceAll($(xml).find('b'))
Edit 3:
This also works:
xml.find('b').replaceWith($('<c>yo</c>'))