Copyright ©

Prototype replace() Method

previous next


This method replaces element by the content of the html argument and returns the removed element.



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.

Return Value:


<title>Prototype examples</title>

<script type="text/javascript" 

function showResult()

   $('first').replace('<ul id="favorite">' +
                          '<li>kiwi</li>' +
   		          '<li>banana</li>' +
   		          '<li>apple</li>' +



  <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>

  <input type="button" value="Click" onclick="showResult();"/>


To understand it in better way you can Try it yourself.

previous next

Copyright ©