src code

class method Form.Element.clear

Form.Element.clear(element) → Element

Clears the contents of a text input. Returns the element.

Example

This code sets up a text field in a way that it clears its contents the first time it receives focus:

  $('some_field').onfocus = function() {
    // if already cleared, do nothing
    if (this._cleared) return
     // when this code is executed, "this" keyword will in fact be the field itself
    this.clear()
    this._cleared = true
  }

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.