1u24Fg5WPmcGc2LsB9kzl changeset

Changeset383037653938 (b)
ParentNone (a)
ab
0+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
0+TR/html4/strict.dtd">
0+<html>
0+        <head>
0+                <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script>
0+                <title>ReplaceWith Chain</title>
0+        </head>
0+        <body>
0+                <div id="old">old</div>
0+                <script type="text/javascript">
0+                        //sorry for the mess in the discussion group this one is really working :-|
0+                        $.fn.replaceWithAndReturnNew = function(html){
0+                                var div = document.createElement('div');
0+                                var replaced = this[0];
0+                                replaced.parentNode.replaceChild(div, replaced);
0+                                div.innerHTML = html;
0+                                var replacer = div.firstChild;
0+                                div.parentNode.replaceChild(replacer, div);
0+                                return $(replacer);};
0+                                                               
0+                        alert($('div#old').replaceWithAndReturnNew('<div>new</div>').html());
0+                </script>
0+        </body>
0+</html>
0+
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--- Revision None
+++ Revision 383037653938
@@ -0,0 +1,25 @@
+<!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>
+