Revision 383037653938 () - Diff

Link to this snippet: https://friendpaste.com/1u24Fg5WPmcGc2LsB9kzl
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!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>