Reputation: 195
I want to add a domain url to an image src without replacing the image name:
Domain Url : http://www.example.com
Before:
<img src="images/old.gif">
After:
<img src="http://www.example.com/images/old.gif">
I have tried using javascript but no luck:
document.getElementById("footer").getElementsByTagName("img")[0].src = "http://www.example.com";
Upvotes: 0
Views: 3190
Reputation: 12566
$("#footer > img").attr("src", "http://site.com/" + $("#footer > img").attr("src") );
Or, you might try check out the base tag:
<head>
<base href="http://www.w3schools.com/images/" target="_blank" />
</head>
<body>
<img src="stickman.gif" />
<a href="http://www.w3schools.com">W3Schools</a>
</body>
Upvotes: 1