Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (document, window) {
- 'use strict';
- /**
- * Creates a random image element
- * @param {HTMLElement|Node} elem
- * @param {String} location
- * @param {Array} images
- */
- var randomImage = function (elem, location, images) {
- if (!Array.isArray(images) || images.length === 0 || !elem || !location) {
- throw "Invalid arguments";
- }
- var img = document.createElement('img');
- img.src = location + images[Math.floor(Math.random() * images.length)];
- elem.appendChild(img);
- };
- // Expose method
- window.randomImage = randomImage;
- }(document, window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement