I want to create a JavaScript function that changes the color of the title when I hover over an image. It seems to be working, but only for the first div. Could it be an issue with my scoping?
Thank you!
<body>
<div>
<a href="" id="img"><img src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" class="img" width="200"></a>
<a href="" id="head1"><h1>test title</h1></a>
</div>
<div>
<a href="" id="img"><img src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" class="img" width="200"></a>
<a href="" id="head1"><h1>test title</h1></a>
</div>
</body>
<script type="text/javascript">
var image = document.getElementById("img");
var text1 = document.getElementById("head1");
function changeTextRed() {
text1.style.color = 'red';
};
function changeTextDefault() {
text1.style.color = 'blue';
};
image.onmouseover = function(){
changeTextRed()
};
image.onmouseout = function(){
changeTextDefault()
};
</script>