What is wrong with this code?
$(function() {
function testfunction() { $(this).addClass('testing');}
$('.tester').testfunction();
});
What is wrong with this code?
$(function() {
function testfunction() { $(this).addClass('testing');}
$('.tester').testfunction();
});
testfunction() is not added to the jQuery function stack.
If you want to be able to call it on an arbitrary object, you should add it to the jQuery function stack:
$.fn.testfunction = function() {
this.addClass('testing');
};
$('.tester').testfunction(); // success!
You should take a look at jQuery's Plugins/Authoring page for more information on how to properly write plugins.
this.each(function() {}); inside the function. For more info, I really encourage you to read the docs.jquery.com/Plugins/Authoring page. It will help you understand the subject better.