This question already has an answer here:
- Javascript Function that changes Text Color, Hyperlink Color, and Image 1 answer
For my assignment, I need to use javascript to change the text color, hyperlink color, and image on this page:
The idea is that when a user clicks "Romantic", the text "Select Mood...", "Your Vacation Awaits!", and "Vacations, LLC" will change to red (more red than they already are), when a user clicks "Adventure", the text will change to blue, etc. Also, the picture will change, along with the color of the hyperlinks. Unfortunately, our teacher only gave us an html file, and it's pretty terrible - inline styles, no use of CSS, etc. I don't know if he sent us a bad file on purpose or if he just doesn't know what he's doing. Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>Castaway Vacations, LLC</title>
<script src="castaway.js"></script>
</head>
<body leftmargin=0 rightmargin=0 bgcolor=#ffcc99
text=#993300 link=#993300 vlink=#996633>
<br>
<table width=100% border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=95% align="right" bgcolor=#ffffff>
<img src="castaway_logo.jpg">
<br>
<font face=arial>Vacations, LLC</font></td>
<td bgcolor=#ffffff> </td>
</tr>
</table>
<br><br>
<div align="center">
<table width=600>
<tr>
<td width=300 valign="top">
<font face=arial size=3><b><i>Select Mood...</i></b></font><br><br>
<font face=arial>
<a onClick="change_color();" href="#">Romantic</a><br><br>
<a onClick="change_color2();" href="#">Adventure</a><br><br>
<a onClick="change_color3();" href="#">Relaxation</a><br><br>
<a onClick="change_color4();" href="#">Family</a><br><br><br><br>
<a href="#">Request A Brochure...</a>
</font>
</td>
<td align="center"><img id="rom_main.jpg" src="orig_main.jpg">
<br><i>Your Vacation Awaits!
</tr>
</center>
</body>
</html>
</DOCTYPE>
And my javascript:
function change_color(){
document.body.style.color = "red";
document.getElementById("orig_main.jpg").src = "rom_main.jpg";
}
function change_color2(){
document.body.style.color = "blue";
document.getElementById("orig_main.jpg").src = "adv_main.jpg";
}
function change_color3(){
document.body.style.color = "green";
document.getElementById("orig_main.jpg.jpg").src = "rel_main.jpg";
}
function change_color4(){
document.body.style.color = "orange";
document.getElementById("orig_main.jpg").src = "fam_main.jgp";
}
As you can see I tried to create four separate functions for when the user clicks on the different links, but nothing is happening. I'm pretty new at javascript and don't really know what I'm doing, so any help or advice is appreciated. Thank you.
JSFiddle Link - demo