I'm trying to build a simple jquery plugin that can take selectors as parameters. All of the examples I find expect more raw 'properties' (width, color, etc) than actual selectors. Are there any good ways to do this?
I found this article : http://stackoverflow.com/questions/541362/passing-jquery-selector-to-sub-function-within-a-plugin
But I'm still relatively confused.
The goal is kind of like this ...
(function ($) {
$.fn.demonstration = function (options) {
var defaults = {
$selector: null
};
var options = $.extend(defaults, options);
return this.each(function () {
alert($selector.attr('id'));
});
};
})(jQuery);
$('body').demonstration({ $selector: $('#canvas') });