0

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
asked Jun 15, 2013 at 12:43
1
  • 3
    Typo? Its extend starting with a lower case e. Commented Jun 15, 2013 at 12:47

1 Answer 1

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

Demo : http://jsfiddle.net/hungerpain/TkA2e/

answered Jun 15, 2013 at 12:49
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.