javascript - Using string.prototype with click -


i'm trying create extension method named .switch() this:

    string.prototype.switch = function (p) {         console.log(this); // should log $obj     };      var $obj = $("div");     $("a", $obj).click(function (e) {         $obj.switch(0);     }); 

html

 <div>    <a href="#">link</a>  </div> 

and i'm getting error: uncaught typeerror: undefined not function

can show me how done?

$obj jquery object, not string. if want add functions it, should in way:

jquery.fn.switch = function (p) {      console.log(this); // should log $obj }; 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -