Of course, there are a whole range of possible errors relating to document validity, but my immediate stumbling block occurs when changing a paragraph (p) into an address element. My current method is (more-or-less):
var p = $('p#test'); p.replaceWith('<address>' + p.html() + '</address>');
but that fails for this specific case; it works perfectly for p -> blockquote or h2 -> h3. Firebug suggests that a self-closing element (<address/>) has been added to the document, for some reason.
Can anyone spot the bug or suggest an alternative method?
Your solution is subject to all sorts of horrible HTML escaping issues and possibly injection attacks.