No title Revision 383037653938 (Fri Dec 23 2011 at 13:01) - Diff Link to this snippet: https://friendpaste.com/1u24Fg5WPmcGc2LsB9kzl Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 123456789101112131415161718192021222324<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script> <title>ReplaceWith Chain</title> </head> <body> <div id="old">old</div> <script type="text/javascript"> //sorry for the mess in the discussion group this one is really working :-| $.fn.replaceWithAndReturnNew = function(html){ var div = document.createElement('div'); var replaced = this[0]; replaced.parentNode.replaceChild(div, replaced); div.innerHTML = html; var replacer = div.firstChild; div.parentNode.replaceChild(replacer, div); return $(replacer);}; alert($('div#old').replaceWithAndReturnNew('<div>new</div>').html()); </script> </body></html>