Prototype update() Method


Advertisements


This method replaces the content of the element with the provided newContent argument and returns the element.

Given newContent can be a 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 updated.

If no argument is provided, Element.update will simply clear element of its content.

Syntax

element.update( newContent );

Return Value

  • Updated HTML element.

Example

<html>
<head>
<title>Prototype examples</title>

<script type="text/javascript" 
   src="/javascript/prototype.js">
</script>
<script>

function showResult()
{
   $('movies').update("Spider Man, USV-315");
}

</script>
</head>

<body>

  <p>Click the button to see the result</p>
  <div id="movies">
      Speed, Titanic, Brave Heart
  </div>

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

</body>
</html>

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


prototype_element_object.htm

Advertisements