Answers for "javascript img"

3

set img src using javascript

document.getElementById("imageid").src="../template/save.png";
Posted by: Guest on May-19-2020
0

show image javascript

HTML:
<img id="theImage" src="yourImage.png">
<a id="showImage">Show image</a>

JavaScript:
document.getElementById("showImage").onclick = function() {
    document.getElementById("theImage").style.visibility = "visible";
}

CSS:
#theImage { visibility: hidden; }
Posted by: Guest on January-30-2021
0

show image javascript

JS:
function setImageVisible(id, visible) {
    var img = document.getElementById(id);
    img.style.visibility = (visible ? 'visible' : 'hidden');
}

HTML:
<img id="myImageId" src="yourImage.png">
Then, your links would be:
<a href="javascript:setImageVisible('myImageId', true)">show image</a>
<a href="javascript:setImageVisible('myImageId', false)">hide image</a>

CSS:
#theImage { visibility: hidden; }
Posted by: Guest on January-30-2021
2

js load img

var elements = [];
function loaded(){
  console.log("you have loaded an image");
}
CreateFileFrom("your/dir/here/img.png");

function CreateFileFrom(dir){

  		/* defining runtime variables */
	  		var extension                        =   dir.split('.').pop();
	  		var keys                             =   {"png":"IMG","jpg":"IMG","jpeg":"IMG",
	  												  "js":"SCRIPT","json":"SCRIPT",
	  												  "mp3":"AUDIO","wav":"AUDIO"};
	  	    var obj                              =   document.createElement(keys[extension]) || {};
	  	    obj.src                              =   dir;
	  	    
	  	/* onload function called when the resource is loaded */
	  	    obj.onload                           =   (e) => {

	  	    	elements.push(e.path[0]);
	  	    	loaded()
	  		}

  		/* make sure that the data is compitable */
  			if(keys[extension]==null){console.error("not supported media type "+extension);return;}
  	}
Posted by: Guest on April-11-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language