My JQuery-UI widget should append a div to itself when clicked. But my button callback doesn't have access to this.element - it's undefined because I assume this refers to the button and not my widget. Please see the simple code below for a better description:
(function ($) {
$.widget( "my.myWidget", {
_create: function () {
this.element.click(this.addRow);
},
addRow: function(evt) {
// this.element is undefined?
console.log("Is this.element defined: " + this.element != undefined);
// cant append to this.element
$('<div></div>')
.appendTo(this.element);
}
});
})(jQuery);
How can I access the widget (this.element) inside my click callback function?