10 examples of 'jquery change image src' in JavaScript

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

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}
67function setImage(element, url) {
68 var property = "url(" + url + ")";
69 element.style.backgroundImage = property;
70}
259function image_load (image) {
260 image_n = images.indexOf(image);
261 var group = image.split("_")[1].split(".")[0].replace(/^[0-9]|[0-9]$/g, "");
262 if (image == "sc_system2.png") {
263 var map = "system";
264 } else {
265 var map = "pn";
266 }
267 document.getElementById('screen').innerHTML ="<IMG class=\"screen1\" src=\"infohtml/" + LastIMG + "\" border=\"0\" usemap=\"#map_" + map + "\">";
268 document.getElementById('screen2').innerHTML ="<IMG class=\"screen2\" src=\"infohtml/" + image + "\" border=\"0\" usemap=\"#map_" + map + "\">";
269 document.getElementById('info').innerHTML = "<CENTER>" + group.toUpperCase() + " (" + (image_n + 1) + "/" + images.length + ")</CENTER>";
270 fade_val = 0.0;
271 document.getElementsByClassName("screen2")[0].style.opacity = fade_val;
272 image_fade();
273 LastIMG = image;
274}
79function preloadImg(image) {
80 var img = new Image();
81 img.src = image;
82}
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}
165function isImageLoaded($img){
166 return $img.get(0).complete;
167};
1275function imageLoaded(image, callback) {
1276
1277 if (!image.nodeName || image.nodeName.toLowerCase() !== 'img')
1278 return callback(new Error('First argument must an image element'));
1279
1280 if (image.src && image.complete && image.naturalWidth !== undefined)
1281 return callback(null, true);
1282
1283 image.addEventListener('load', function() {
1284 callback(null, false);
1285 }.bind(this));
1286
1287 image.addEventListener('error', function(e) {
1288 callback(new Error('Failed to load image \'' + (image.src || '') + '\''));
1289 }.bind(this));
1290
1291 if (image.complete) {
1292 src = image.src;
1293 image.src = BLANK;
1294 image.src = src;
1295 }
1296}
5function loadImage(currentImage){
6 var oImage = new Image();
7 oImage.src = currentImage.getAttribute('data-src');
8 oImage.onload = function(){
9 currentImage.src = this.src;
10 currentImage.className = 'on';
11 oImage = null;
12 }
13 currentImage.setAttribute('isLoad' ,true);
14}
79function setLoaded(targetImg, e) {
80 targetImg.style.display = 'block';
81 targetImg.src = e.target.result;
82}

Related snippets