Dom
Dom

Reputation: 3126

jQuery very simple plugin

I have created my firs plugin with jquery and it simply dont work as it should.

Can someone please correct me, and if possible send me to some jQuery tutorials?

Im trying to grab label value and pass it to another input

jQuery.fn.checktoclient = function () {
return this.each (function () {

this.map(function(){

        return $(this).text()

    }).get();

});
};
var radio1_val = $('input[name="form[radio1]"]:checked + label').checktoclient();

$('input#radioclient').val(radio1_val);

May thanks for your help.

Dom

Upvotes: 0

Views: 104

Answers (1)

icyrock.com
icyrock.com

Reputation: 28588

Take a look at the jQuery plugin Getting started itself:

In the The Basics part, you have a plugin function maxHeight that does exactly what you want, except that it doesn't return the text, but height. I suggest you read it - there are a few other things that you should be doing, summarized at the end, so it will be useful.

Btw, the reason it is not working is because .each() returns the jQuery itself, so your function is returning the jQuery object, not the text you were expecting - look at the Returns on the .each() API documentation:

Upvotes: 3

Related Questions