Following is the the snippet of a widget:
(function($){
var ele,_this;
$.widget('test.mywidget',{
_loadComments:function(d)
{
$.each(d,function(k,v){
var p=$('<div/>').addClass('comment').attr('id',v.id);
p.append("<textarea class='ui-border' onkeypress='_this._submitReply()'></textarea>");
ele.find('.prevComments').append(p);
});
},
_submitReply:function(){}
_attachEvent:function()
{
ele.on('change','textarea',function(){
alert('ta pressed');
});
}
_create:function(){
ele=this.element;
_this=this;
this._loadComments(somedata);
this._attachEvent();
}
});
});
The problem is if this._loadComments(somedata); has two record and then if i press key inside textarea alert('ta pressed'); get called 2 times, if it is 10 data it is called 10 times. It should not happens like this. It should call alert message only once for individual textarea.
How can i attach event to individual element? I think here I am attaching event to all textarea that's why.
If i add inline event like onkeypress='_this._somefunction()' it says _this is undefined but it is there.
this.element.on('change'eleis the same thing