views:

1666

answers:

1

I got a simple UI widget and i'd like it to alert() the "hello world!!!" when initialised.

$.widget("ui.myWidget", {
   _init: function() {
      //start
      alert('Hello World!!!');
   }
}

could some one explain how this init or _init function works.? if i was to call the ui just like the dialog ui would $('#selector').dialog() in other words if a click <div onclick="$('#id').myWidget()">Click Me</div> then i should get the alert to pop up.

this code is short because i didnt want to put a lot of coding into it so its easy to read. thanks

+1  A: 

Yes when you call $('#id').myWidget(); it will trigger your _init function to run and fire the alert.

Here is a short post about using the jQuery UI widget factory

PetersenDidIt