Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery extends element

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.

like image 209
user1229834 Avatar asked Apr 27 '26 23:04

user1229834


1 Answers

Like this:

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

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

EDIT: complete statement

lg,

flo

like image 194
Florian Avatar answered Apr 30 '26 11:04

Florian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!