I have been trying to use the following piece of code to change the src of an image
document.getElementById('test').src='images/test2.png';
My code looks like this. There's some CSS and other things in there but the important parts are the div and the img, and the function.
<div id='splashScreen' class='splash'>
<button class='bigButton' onclick='introSplash()'>Hi</button>
<img class='splashImages' src='images/splashScreen1.png'>
</div>
this is my image with a page-sized transparent button over the top of it
<script>
function introSplash() {
document.getElementById('splashImages').src='images/splashScreen2.png';
}
</script>
this function should be replacing the image under the button.
Pressing the button with this code returns the following error message:
Uncaught TypeError: Cannot set property 'src' of null at introSplash
all of the images are locally saved and exist with those names
I'm not sure why this is occurring, and would appreciate any help.