How to create a function with multiple functions
I have several functions in my .js file: (This is just an example, I know that the function is the same in this case)
- ;(function($) {
$.fn.randomImage = function(options) {
return this.each(function() {
var defaults = {images: [
'<a href="page1.html"><br>Asia<br><img src="https://lh6.googleusercontent.com/-CMBwAQFvgmc/ULwxL0ciUfI/AAAAAAAAAA8/RhaVA3N_TKM/s720/Asia.JPG" height=125 width=200></a>',
'<a href="page2.html"><br>Africa<br><img src="https://lh6.googleusercontent.com/-LZx9rZ_N7ZQ/ULwyGe1sOPI/AAAAAAAAABE/8iQpB5O7yys/s720/Africa.jpg" height=125 width=200></a>']};
var settings = $.extend(defaults, options || {});
$(this).append(settings.images[Math.floor(Math.random() * settings.images.length)]);
});
};
$.fn.randomImage2 = function(options) {
return this.each(function() {
var defaults = {images: [
'<a href="page1.html"><br>Asia<br><img src="https://lh6.googleusercontent.com/-CMBwAQFvgmc/ULwxL0ciUfI/AAAAAAAAAA8/RhaVA3N_TKM/s720/Asia.JPG" height=125 width=200></a>',
'<a href="page2.html"><br>Africa<br><img src="https://lh6.googleusercontent.com/-LZx9rZ_N7ZQ/ULwyGe1sOPI/AAAAAAAAABE/8iQpB5O7yys/s720/Africa.jpg" height=125 width=200></a>']};
var settings = $.extend(defaults, options || {});
$(this).append(settings.images[Math.floor(Math.random() * settings.images.length)]);
});
};
I would like to know if there is any way that I could create a function to call both functions within the same, in the same .js file in jQuery something like:
Function callAllFunction (
randomImage
randomImage2
)
So when I call the function in my HTML code I will call only the "callAllFunction" instead of having to call one by one each of the functions.
Thanks so much