src code

instance method Element#update

Element#update([newContent]) → Element

Replaces the content of element with the newContent argument and returns element.

newContent may be in any of these forms:

  • String: A string of HTML to be parsed and rendered
  • Element: An Element instance to insert
  • ...any object with a toElement method: The method is called and the resulting element used
  • ...any object with a toHTML method: The method is called and the resulting HTML string is parsed and rendered

If newContent is omitted, the element's content is blanked out (i.e., replaced with an empty string).

If newContent is a string and contains one or more inline <script> tags, the scripts are scheduled to be evaluated after a very brief pause (using Function#defer) to allow the browser to finish updating the DOM. Note that the scripts are evaluated in the scope of String#evalScripts, not in the global scope, which has important ramifications for your vars and functions. See String#evalScripts for details.

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.