JQuery Plugin Example Structure

by bizamajig

HTML

<div>Test</div>
<div>Test2</div>

JavaScript

jQuery.fn.myFunction = function() {
        // Usually iterate over the items and return for chainability:
        return this.each(function() { 
             // do something to each item matching the selector
            alert($(this).text());
        });
};
                         
$('div').myFunction();