Tutorial :jquery init function


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


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »