a | b | |
---|
| 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 | + | |
---|
... | |
---|