9 examples of 'change image src javascript' in JavaScript

Every line of 'change image src javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
78function getImageSrc(src) {
79 return window.isLocal ? '/demo/' + src : src;
80}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

21function addImage(src, width, height)
22{
23 var img = document.getElementById("img-container").firstElementChild;
24 img.width = width;
25 img.height = height;
26 img.src = src;
27}
42setSrc(src) {
43 this._planet && this._planet._geoImageCreator.remove(this);
44 this._src = src;
45 this._sourceReady = false;
46}
227function setImage(id, path) {
228 document.getElementById(id).src = imageDir + path;
229}
122function setImage(el, src) {
123
124 var image = new Image();
125
126 image.onload = function() {
127 el.setAttribute('src', src);
128 };
129
130 image.src = src;
131}
19setSrc(src) {
20 this.img.src = src
21}
42set src(v) {
43
44 this._src = v;
45
46 GImage.GBridge.perloadImage([this._src, this._id], (data) => {
47 if (typeof data === 'string') {
48 data = JSON.parse(data);
49 }
50 if (data.error) {
51 var evt = { type: 'error', target: this };
52 this.onerror(evt);
53 } else {
54 this.complete = true;
55 this.width = typeof data.width === 'number' ? data.width : 0;
56 this.height = typeof data.height === 'number' ? data.height : 0;
57 var evt = { type: 'load', target: this };
58 this.onload(evt);
59 }
60 });
61}
246function createImageSrc(content) {
247 var mimeType = Lib.extractMimeType(content.mimeType);
248 // https://css-tricks.com/data-uris/
249 return "data:" + mimeType + ";base64," + content.text;
250}
176function changeImg(index) {
177 var list = obj1.getElementsByTagName('img');
178 var list1 = obj1.getElementsByTagName('font');
179 for (i = 0; i < list.length; i++) {
180 list[i].style.display = 'none';
181 list1[i].style.backgroundColor = 'white';
182 }
183 list[index].style.display = 'block';
184 list1[index].style.backgroundColor = 'blue';
185}

Related snippets