3

I want to extend the functionality of my textarea element. The textarea elements should respond when I call a method like this:

$('#jsedit').jsedit();

I know it can be done by doing like this:

$(function() {
    $.fn.extend({
        jsedit: function() {
            alert(this.val());
        }
    });
});

but how can I specify only the textarea can do this? Because now every element can called jsedit() method.

1 Answer 1

2

Like this:

$(function() {
    $.fn.extend({
        jsedit: function() {
            if ($(this).is('textarea')) {
                 //your stuff
            }
        }
    });
});

console.log($('#your_textarea').jsedit());

EDIT: complete statement

lg,

flo

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

1 Comment

or, pure javascript too: if(this.nodeName === 'TEXTAREA') { ... }

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.