10 examples of 'jquery change img src' in JavaScript

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

79function preloadImg(image) {
80 var img = new Image();
81 img.src = image;
82}
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}
165function isImageLoaded($img){
166 return $img.get(0).complete;
167};
79function setLoaded(targetImg, e) {
80 targetImg.style.display = 'block';
81 targetImg.src = e.target.result;
82}
78function getImageSrc(src) {
79 return window.isLocal ? '/demo/' + src : src;
80}
19function showImg(id, src) {
20 startTimes[id] = (new Date()).getTime();
21 document.getElementById(id).src = src;
22}
141function loadImage(tmp, src){
142 $(tmp.find('#avatarUserImg')).attr('src', src);
143 $(tmp.find('#preview img')).attr('src', src);
144 $(tmp.find('#realImage')).attr('src', src);
145};
1function changeImg() {
2 var imgSrc = $("#imgObj");
3 var src = imgSrc.attr("src");
4 imgSrc.attr("src", chgUrl(src));
5}
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}

Related snippets