Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Prototype replace() Method


previous next AddThis Social Bookmark Button


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

Syntax:

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.

Return Value:

  • Returns the removed HTML element.

Example:

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



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names