-1
Hello, I am starting to learn programming now and I need help to solve a little problem and I have a problem that I believe is easy to solve. This is the problem:
function Antes() {
document.getElementById('ant').style.backgroundColor = "#c3c3c4";
}
function antes() {
document.getElementById('ant').style.backgroundColor = "black";
}
function Depois() {
document.getElementById('pro').style.backgroundColor = "#c3c3c4";
}
function depois() {
document.getElementById('pro').style.backgroundColor = "black";
}
function Close() {
document.getElementById('close').style.color = "#c3c3c4";
}
function fechar() {
document.getElementById('close').style.color = "white";
}
<div class="lbox" id="img1">
<div class="box_image"></div>
<a href="#img6" class="btn" id="ant" onmousemove="Antes()" onmouseout="antes()">«</a>
<a href="#img2" class="btn" id="pro" onmousemove="Depois()" onmouseout="depois()">»</a>
<a href="" class="btn" id="close" onmousemove="Close()" onmouseout="fechar()">X</a>
<img src="imagens/combate-ao-aedes-aegypti-2.jpg" alt="" id="imgm1">
</div>
</div>
<div class="lbox" id="img2">
<div class="box_image">
<a href="#img1" class="btn" id="ant" onmousemove="Antes()" onmouseout="antes()">«</a>
<a href="#img3" class="btn" id="pro" onmousemove="Depois()" onmouseout="depois()">»</a>
<a href="" class="btn" id="close" onmousemove="Close()" onmouseout="fechar()">X</a>
<img src="imagens/dengue-cuidados.png" alt="" id="imgm2">
</div>
The intention is to make the a href
change the background color when hover the mouse above
I managed with this code to perform this action in only with the "a href" of div#img1 (in the case of a#ant, a#pro and a#close of div#img1) but in the other div’s not.
When you want to style something, it is strongly recommended to use only CSS for such an action, using as little Javascript as possible. What you want to do is possible using CSS only.
– Felipe Pereira
if using the pseudoclass
: hover
you won’t need anythingjavascript
– Ricardo Pontual