anthonyvd
anthonyvd

Reputation: 7590

Define a UI element like the ones in jQuery UI

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

Answers (2)

Sinetheta
Sinetheta

Reputation: 9429

worlds smallest jQuery plugin! jsfiddle

$.fn.myFunc = function(){
    alert($(this).length)
};
$('div').myFunc();

Upvotes: 2

Lucius
Lucius

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

Related Questions