I'm new to coding, but am enjoying the learning experience. I've run into something I can't solve.
I hope this makes sense.
Here is the code I am using.
<script>
function switchDefault() {
document.getElementById('switch_image').src = "img/portfolio/profileimage.png";
}
function switchRed() {
document.getElementById('switch_image').src = "img/imagetest/redshirt.png";
}
function switchYellow() {
document.getElementById('switch_image').src = "img/imagetest/yellowshirt.png";
}
</script>
<img src="img/portfolio/profileimage.png" id="switch_image"
onmouseover="this.src='img/portfolio/profileimagemove.png'"
onmouseout="this.src='img/portfolio/profileimage.png'"
/>
<button type="button" onclick="switchRed()">Switch Red!</button>
<button type="button" onclick="switchYellow()">Switch Yellow!</button>
<button type="button" onclick="switchDefault()">Switch Back To Default!</button>
I know it's probably not very good, but I'm new to this.
Here is a detailed description of what I am attempting:
I want to change an image src to different img src when I click a button. That's done and it works fine. However, I would like to have a different mouseover effect dependant upon which image has been displayed. For example, if the switchYellow()
function has been run, I want the mouseover effect to display "blueshirt.png"
If the switchRed()
function has been run, I want the mouseover effect to display "greenshirt.png"
Any help is appreciated! Thank you!