Call jQuery function within function
I have a jQuery function (stripped down just for this example):
(function($) {
$.fn.Lightbox = function(options) {
var opts = $.extend(defaults, options);
开发者_运维问答 function initialize() {
$('#lightbox').show();
return false;
};
function close() {
$('#lightbox').hide();
};
return this.click(initialize);
};
})(jQuery);
I then use....
$('a.image').Lightbox();
to run it. I want to be able to call the close() function seperately e.g.
$.Lightbox.close();
How can I achieve this within my code?
You can add a method for that, like this:
(function($) {
$.fn.Lightbox = function(options) {
var opts = $.extend(defaults, options);
function initialize() {
$('#lightbox').show();
return false;
};
function close() {
$('#lightbox').hide();
};
return this.click(initialize);
};
$.Lightbox = {
close: function() {
$('#lightbox').hide();
}
};
})(jQuery);
精彩评论