user188962
user188962

Reputation:

Why doesn't the image 'src' gets replaced with this javascript?

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

Upvotes: 0

Views: 134

Answers (3)

YOU
YOU

Reputation: 123937

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

Upvotes: 1

rahul
rahul

Reputation: 187110

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.

Upvotes: 1

Zack
Zack

Reputation: 2846

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

Upvotes: 5

Related Questions