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();
Adil Shaikh
44.8k17 gold badges96 silver badges112 bronze badges
1 Answer 1
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 :
- The typo, its not Extend, its extend
- Its
this, not$(this)inside extend
answered Jun 15, 2013 at 12:49
krishwader
11.4k1 gold badge36 silver badges52 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
extendstarting with a lower casee.