1//change image src
2document.getElementById('myImageID').src="images/my_other_image.png";
1var elements = [];
2function loaded(){
3 console.log("you have loaded an image");
4}
5CreateFileFrom("your/dir/here/img.png");
6
7function CreateFileFrom(dir){
8
9 /* defining runtime variables */
10 var extension = dir.split('.').pop();
11 var keys = {"png":"IMG","jpg":"IMG","jpeg":"IMG",
12 "js":"SCRIPT","json":"SCRIPT",
13 "mp3":"AUDIO","wav":"AUDIO"};
14 var obj = document.createElement(keys[extension]) || {};
15 obj.src = dir;
16
17 /* onload function called when the resource is loaded */
18 obj.onload = (e) => {
19
20 elements.push(e.path[0]);
21 loaded()
22 }
23
24 /* make sure that the data is compitable */
25 if(keys[extension]==null){console.error("not supported media type "+extension);return;}
26 }