jQuery.Controller.prototype.element  attribute     

The controller instance's delegated element. This is set by setup. It is a jQuery wrapped element.

For example, if I add MyWidget to a '#myelement' element like:

$.Controller("MyWidget",{
  init : function(){
    this.element.css("color","red")
  }
})

$("#myelement").my_widget()

MyWidget will turn #myelement's font color red.

Using a different element.

Sometimes, you want a different element to be this.element. A very common example is making progressively enhanced form widgets.

To change this.element, overwrite Controller's setup method like:

$.Controller("Combobox",{
  setup : function(el, options){
     this.oldElement = $(el);
     var newEl = $('<div/>');
     this.oldElement.wrap(newEl);
     this._super(newEl, options);
  },
  init : function(){
     this.element //-> the div
  },
  ".option click" : function(){
    // event handler bound on the div
  },
  destroy : function(){
     var div = this.element; //save reference
     this._super();
     div.replaceWith(this.oldElement);
  }
}
© Jupiter IT - JavaScriptMVC Training and Support