Reputation: 37
I have tried to extend my jquery the following way, it isn't working.
var y = {
alertData: function () {
alert('z');
},
hideData: function () {
$(this).hide();
}
};
var z = $('#a');
$.Extend(z, y);
z.hideData();
Upvotes: 0
Views: 46
Reputation: 11371
Maybe try extending like this?
$.fn.extend({
alertData: function () {
alert('z');
return this;
},
hideData: function () {
this.hide();
return this;
}
});
And using it like this on an element with a
as id?
$('#a').alertData().hideData();
The reason your implementation wasn't working was :
this
, not $(this)
inside extendDemo : http://jsfiddle.net/hungerpain/TkA2e/
Upvotes: 1