I need some help writing a jQuery widget.
As an exercise, I am trying to create a widget which adds a 'Hello World' message to the selected element when the page is loaded.
The below code should append "Hello World" to div with class "123", but nothing happens. Can anyone see what I did wrong?
jQuery/javascript:
$.widget("custom.hwLoader",{
options: {
clear:null
},
_create: function() {
this.element;
this.name;
this.namespace;
this.element.on("load"+this.eventNamespace,
function(){
$("<h1>Hello World</h1>").appendTo(this.element);
}
)
},
_setOption: function( key, value ) {
this._super("_setOption", key, value );
},
_destroy: function() {
this.element.unbind('.'+this.eventNamespace);
}
});
HTML:
$("<div class='addHere'></div>").appendTo("body");
$(".addHere").hwLoader();