0

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/

1
  • 3
    i suggest you read more about plugin authoring. it's pretty much explained here how to do what you are doing. Also, use a boilerplate so that you won't be scratchcoding all the time. Commented Apr 7, 2012 at 4:56

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for that ,i got the idea about the chainability ,but i cannot do this by just returning the selector ,because the taggable input is not actually a input of type text [or some element that can return the value] it is a combination of ul and li ,is there any other way ?
I can't tell what this script is trying to accomplish. Can you condense it to something more or less in this format: jsfiddle.net/nathanjosiah/aCP7X
You are in the right way ,returning the values means that getting all the text values of all li elements inside the ul
You are providing the code ,not a method to do this,i am trying to get some ideas about Plugin Methods.
I apologize, your question is very vague and it appears you were just looking for code to solve the problem.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.