views:

41

answers:

3
var x = document.getElementById("pic");
    x.src='path.jpg';

Shouldn't this replace the source of the the image with the id 'pic' ?

What am I doing wrong?

When I right-click and check the source of the html in my browser, the image 'src' have not yet been changed!

Thanks

+5  A: 

You wouldn't see the change reflected in the source. You need something like FireBug to see changes to the DOM.

Zack
To be specific, View Source shows the page as it was downloaded, not as it's been modified by Javascript since rendering.
T. Stone
+1  A: 

Just right click the image and then check the image path. It should reflect the updated one. The HTML source is downloaded when you make a page request from the browser to the server. It won't be affected when you change the image source or append some content dynamically to the page using javascript.

rahul
+1  A: 

If you use Firefox, use Alt+Click to select the image, and try View Selection Source from context menu.

S.Mark