truslivii.lev
truslivii.lev

Reputation: 701

Custom jQuery plugin doesn't work properly

I tried to create my own tiny jQuery plugin to fill and clear a textarea:

$.fn.fillTextarea = function ( startVal ) {
    var messBox = $(this).val(startVal);

    messBox.on('focus blur', function () {
        var curVal = $.trim($(this).val());
        if (curVal == startVal) {
            $(this).val('');
        } else if (!curVal) {
            $(this).val(startVal);
        }
    });
};


$(document).ready(function () {
    $('.number-1').fillTextarea({
        'startVal' : 'test'
    });
});

But when I try to use it I get [object Object] in the textarea instead of my startVal.
http://jsfiddle.net/3QHWe/1/

What's wrong with my code? How can I fix it?

Upvotes: 0

Views: 24

Answers (1)

function ( startVal ) {
       // ^ is object which is passed

to get the it's key value value use object.key

$('.number-1').fillTextarea({
    'startVal' : 'test'
    //^Key        Value

Use startVal.startVal to get value that is text

Fiddle Demo

Upvotes: 1

Related Questions