Copyright © tutorialspoint.com
This method replaces element by the content of the html argument and returns the removed element.
element.replace(html); |
Here html can be either plain text, an HTML snippet or any JavaScript object which has a toString() method.
If it contains any <script> tags, these will be evaluated after element has been replaced.
NOTE: If no argument is provided, Element.replace will simply clear element of its content.
<html> <head> <title>Prototype examples</title> <script type="text/javascript" src="/javascript/prototype.js"> </script> <script> function showResult() { $('first').replace('<ul id="favorite">' + '<li>kiwi</li>' + '<li>banana</li>' + '<li>apple</li>' + '</ul>'); } </script> </head> <body"> <p id="test">Click the button to see the result.</p> <div id="food"> <div id="fruits"> <p id="first">Kiwi, banana <em>and</em> apple.</p> </div> </div> <input type="button" value="Click" onclick="showResult();"/> </body> </html> |
To understand it in better way you can Try it yourself.
Copyright © tutorialspoint.com