Zane WilsonFront End Web Development Techdegree Student 2,973 Points
Placeimg random image
In the training video, when Treasure refreshes the page - it loads a new image every time. However, when I refresh the page, the image stays consistent and their is no randomization.
Is this because of the browser I'm using or is this something that I'm doing wrong when I'm inserting the code?
Code for the header is below -
<header> <img src="https://placeimg.com/400/400/people" alt="Drawing of Jane Smith" class="profile-image"> <h1 class="tag name">Hello, I’m Zane.</h1> <p class="tag location">My home is New York, New York.</p> </header>
Thanks in advance!
Steven Parker195,561 Points
Here's the answer I've given previously (as Regan observed), complete with syntax coloring:
Most likely, your browser is trying to be efficient by caching the image. Try doing a no-cache reload if your browser has that function (most do).
document.querySelector("img").src += "?nocache=" + Math.random();
Note that this particular script only targets the first image on the page.