Reputation: 6378
I am new to jQuery plugin creation and created a plugin for my project [Tumblr style tagging].
[I know there are so many plugins available but i want to create myself :D]
here it goes
(function($) {
$.fn.Tagger = function ()
{
this.each(function()
{
//codes goes here
});
};
})(jQuery);
so that after doing this i can do something like this to create taggable input
$("#IdOfTheElement").Tagger();
Now i created the UI and need to get the value of the UI.
For example user types meta
as google
, yahoo
,msn
....
so that i need to get the values as google,yahoo,msn
.
i want to know the method of doing this [not the code]
something like this available ?
$("#ID").Tagger("value"); //returns the values
or
$("#ID").Tagger().val(); // is this possible ?
Hope you understand the question ,all comments/suggestions are welcome.
Please help me complete.
Thank you.
Update
Please check this fiddle http://jsfiddle.net/pNqUL/
Upvotes: 0
Views: 170
Reputation: 6378
I collected all of my plugin's methods in an object literal and called them by passing the string name of the method to the plugin [as per the tutorial says...].
so to apply the tagger i can do
$("#ID").tagger(); // making element as taggable
$("#ID").tagger("value") //returns the value of tagged elements
Upvotes: 0
Reputation: 4459
The last on you specified is possible by changing the code to this:
(function($) {
$.fn.Tagger = function ()
{
return this.each(function()
{
//codes goes here
});
};
})(jQuery);
by returning the orignal selector match you are able to continue the daisy chain of commands. so if $('#ID')
was a form field, then $("#ID").Tagger().val();
would return the value
Upvotes: 1