Search code examples
javascriptjqueryjquery-uijquery-ui-widget

this and $(this) in widget


What do this and $(this) mean inside a widget method like create?

For example, Having a widget like this,

$.widget("sample.CustomWidget", {
options:{
},
_create: function(){
// Here what do this and $(this) mean
}
});

Thanks in advance,

-Raja.


Solution

  • It basically depends on the caller of the _create method... anyway:

    • this refers to the 'owner' of the Function

    • $(this) is the above object wrapped into a jQuery object

    see also:

    http://www.quirksmode.org/js/this.html

    http://www.bennadel.com/blog/1838-Wrapping-The-Window-Object-In-A-jQuery-Wrapper.htm