10 examples of 'javascript change img src' in JavaScript

Every line of 'javascript change img 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
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}
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

1function changeImg() {
2 var imgSrc = $("#imgObj");
3 var src = imgSrc.attr("src");
4 imgSrc.attr("src", chgUrl(src));
5}
78function getImageSrc(src) {
79 return window.isLocal ? '/demo/' + src : src;
80}
16function updateSrcImg() {
17 console.log(new Date(), 'Get input image');
18 var src = "https://storage.googleapis.com/" + document.imageBucket + "/annotated/" + $('#deviceId').val() + "/annotated.jpg"
19 $('#src_image').attr('src', src + '?' + new Date().getTime());
20}
19function showImg(id, src) {
20 startTimes[id] = (new Date()).getTime();
21 document.getElementById(id).src = src;
22}
35function imgSrc() {
36 var w,h;
37 if (document.body && document.body.clientWidth) {
38 w = document.body.clientWidth;
39 h = document.body.clientHeight;
40 } else if (document.documentElement // Explorer 6 Strict Mode
41 && document.documentElement.clientHeight) {
42 w = document.documentElement.clientWidth;
43 h = document.documentElement.clientHeight;
44 } else if (self.innerHeight) { // all except Explorer
45 w = self.innerWidth;
46 h = self.innerHeight;
47 }
48
49 var chart = "line.class";
50 if (window.location.search.indexOf("chart=xy") != -1)
51 chart = "xy.class";
52 else if (window.location.search.indexOf("chart=pie") != -1)
53 chart = "pie.class";
54 else if (window.location.search.indexOf("chart=bar") != -1)
55 chart = "bar.class";
56 else if (window.location.search.indexOf("chart=radar") != -1)
57 chart = "radar.class";
58 return (chart + window.location.search + "&width="+w + "&height="+h);
59}
141function generate_img_src (file_name, img_type_index, use_small=false) {
142 var image_extension = DEFAULT_IMAGE_EXTENSIONS[img_type_index];
143 if (use_small && SMALL_IMAGE_EXTENSIONS.indexOf(image_extension) >= 0) {
144 image_extension = image_extension.split(".")[0] + "_small.png";
145 }
146 return DATA_PATH + file_name + "/" + file_name + image_extension
147
148}
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}
328function addImgHandler(id, index) {
329
330 var el = document.getElementById(id);
331
332 el.addEventListener('click', function() {
333
334 for (var i = 0; i < materials.length; i++) {
335
336 materials[i].map = currentMaps[index];
337
338 }
339
340 currentIndex = index;
341
342 });
343
344}
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}

Related snippets