Reputation: 8343
I must be missing something very basic & think I need a cardboard partner. I've added a new method to jQuery, yet, as in the firebug command-line experience below, it just doesn't work because the method doesn't exist.
The jQuery tutorials all say to write exactly this code, what is wrong with it?
$.fn.bob = function() {alert('bob!');}
>function()
$.bob()
>TypeError: $.bob is not a function
Upvotes: 0
Views: 67
Reputation: 10221
$.fn
refers to the jQuery function $()
:
So your function would have to be called like this:
$('anything').bob();
You can also extend the jQuery object directly, and call the function as you intended:
$.bob = function(){ alert('bob!') }
$.bob();
Upvotes: 3