I'm struggling to get my head around the way I author (and attach to events) in a custom jQuery plugin.
I have the start of a plugin, in this simple example....
http://jsfiddle.net/ETFairfax/mRAHF/9/
(function($) {
$.fn.myPlugIn = function(options) {
var defaults = {
'width': 200,
'url': 'www.someurl.com'
};
// If options exist, lets merge them with our default settings
var options = $.extend({}, defaults, options);
function somePrivateFunction() {
return options.url;
}
return this.each(function() {
$(this).text(somePrivateFunction());
$(this).width(options.width);
});
};
})(jQuery);
$(document).ready(function() {
$('#testDiv1').myPlugIn({
'width': 150
});
$('#testDiv2').myPlugIn({
'url': 'www.google.com'
});
});
<div id="eventDriver1">Click here to update 1</div>
<div id="eventDriver2">Click here to update 2</div>
<div id="testDiv1" class="testClass"></div>
<div id="testDiv2" class="testClass"></div>
As you can see I set testDiv1, and testDiv2, and they behave as I'd expect.
Now I want to be able to say that eventDriver1 should refresh testDiv1, and for it to specify what text shoudl go into it. I just don't know where to start!!
I appreciate that will have been documented somewhere, and/or asked already, but I'm just not sure what buzzwords I need to search for!!! Any help appreciated.
Thanks.
.bind()or.live()or by using one of the shortcuts (such as.click(),.submit(),.load(), etc). I'm not really sure what your question is...