Reputation: 79
Hello JavaScript guru's. I have a simple JS question on how to replace all IMG src path's on a page.
Currently, my IMG tags look like:
<img src="path/to/image.jpg" alt="" />
Output desired:
<img src="../image.jpg" alt="" />
So, when a page is loaded, it will loop through all the IMG tags and replace the SRC path. Thanks in advance for the assistance!
Upvotes: 3
Views: 2038
Reputation: 31951
for (var image, src, images = document.images, l=images.length, i=0; i<l; i++){
image = images[i];
src = image.src;
image.src = ".." + src.substring(src.lastIndexOf("/"));
}
Upvotes: 5