Reputation: 7590
In jQuery UI, widgets are created like this:
$("#selector").accordion({ //options });
How would I go about creating my own widget that would be created like this? Mainly, I need to know how to define a function that can be called on a DOM element (I'm a javascript newbie and the jQuery UI code isn't so readable).
Upvotes: 2
Views: 137
Reputation: 9429
worlds smallest jQuery plugin! jsfiddle
$.fn.myFunc = function(){
alert($(this).length)
};
$('div').myFunc();
Upvotes: 2
Reputation: 3745
Learn how to create a jQuery plug-in. It's pretty great for organizing your code and makes it easier to reuse functionality.
Upvotes: 1