Copyright ©

Prototype insert() Method

previous next


This method inserts content before, after, at the top of, or at the bottom of element, as specified by the position property of the second argument. If the second argument is the content itself, insert will append it to element.

Insert accepts the following kind of content:

NOTE: Note that if the inserted HTML contains any <script> tag, these will be automatically evaluated after the insertion


element.insert({ position: content });



Return Value:


<title>Prototype examples</title>

<script type="text/javascript" 

function showResult(){
   var str = $('apple').insert(  "<li>mangoes</li>" );
   alert(str.innerHTML );


  <p>Click the button to see the result.</p>

   <li id="apple">apple</li>

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


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

Second argument as a postion: Try it yourself.

previous next

Copyright ©