10 examples of 'js change image src' in JavaScript

Every line of 'js 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

19setSrc(src) {
20 this.img.src = src
21}
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}
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}
264function loadResizeImage(src) {
265 var sourceImage = document.getElementById('img');
266 var MAX_WIDTH = 900;
267 var img = new Image();
268 img.crossOrigin = 'anonymous';
269 img.src = sourceImage.src;
270 img.onload = function() {
271 context.clearRect(0, 0, canvas.width, canvas.height);
272
273 if (img.width > MAX_WIDTH) {
274 img.height *= MAX_WIDTH / img.width;
275 img.width = MAX_WIDTH;
276 sourceImage.height = img.height;
277 sourceImage.width = img.width;
278 }
279 canvas.width = img.width;
280 canvas.height = img.height;
281 canvas.style.display = "inline-block";
282
283 drawGrayscaleImage(img);
284 var myData = context.getImageData(0, 0, canvas.width, canvas.height);
285 tracking.Image.computeIntegralImage(myData.data, myData.width, myData.height, result);
286 clearRectangles();
287 }
288}
54function loadImg(src, callback) {
55 var img = new Image();
56 img.src = src;
57 img.onload = function(event) {
58 loadImg.loaded++;
59 callback && callback(event);
60 };
61 return img;
62}
868function loadImage(src, callback) {
869 var img = new Image();
870 img.onload = function () {
871 callback.apply(this, arguments);
872 };
873 img.src = src;
874 return img;
875}
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}
52img.onload = function onImgLoad() {
53 ctx.drawImage(img, 0, 0, width * multiplier, height * multiplier)
54 const dataURL = canvas.toDataURL('image/png')
55 clbck(dataURL)
56}
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}

Related snippets