troubleshooting Question

JavaScript replace img path for all images

Avatar of yando18
yando18 asked on
13 Comments1 Solution2060 ViewsLast Modified:
Hello all,

What I'm trying to accomplish here is to replace all the image paths once a user loads the page. The code that I have below uses getElementById which only grabs the first element instead of getting all of them and replacing the paths. Any help would be great thanks so much.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image Path</title>

<script type="text/javascript">

window.onload = updateSource;
function updateSource()
	var src = document.getElementById('imgId').getAttribute("src");
	src = "/" + src;
	document.getElementById('imgId').src = src;




<img src="i/mo/arrow_left.gif" id="imgId" />
<img src="i/mo/arrow_right.gif" id="imgId" />
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros