10 examples of 'javascript change image src' in JavaScript

Every line of 'javascript change image src' 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}
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}
42setSrc(src) {
43 this._planet && this._planet._geoImageCreator.remove(this);
44 this._src = src;
45 this._sourceReady = false;
46}
19setSrc(src) {
20 this.img.src = src
21}
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}
227function setImage(id, path) {
228 document.getElementById(id).src = imageDir + path;
229}
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}
13xtr_setImage(value: Image | undefined) {
14 if (this._image) {
15 this.nativeObject.removeChild(this._image.source)
16 }
17 this._image = value;
18 if (value) {
19 this.nativeObject.appendChild(value.source)
20 this.resetRatio();
21 this.resetTintColor();
22 }
23}
1458function makeImage() {
1459 var url = document.getElementById('imgUrlPrefix').textContent;
1460 url += escapeField(imageMaker.subject.value);
1461 url += '-' + escapeField(imageMaker.status.value);
1462 url += '-' + escapeField(imageMaker.color.value);
1463 url += '.svg';
1464 document.location = url;
1465}

Related snippets