2
I wish to make a kind of Hide and show on Divs, with jquery. However, changes are not made in the case of round trip.
$(function() {
$('#red').click(function() {
$('.red').css('display', 'block');
$('.blue').css('display', 'none');
$('.green').css('display', 'none');
})
$('#blue').click(function() {
$('.red').css('display', 'none');
$('.blue').css('display', 'block');
$('.green').css('display', 'none');
})
$('#green').click(function() {
$('.red').css('display', 'none');
$('.blue').css('display', 'none');
$('.green').css('display', 'block');
})
})
.red {
width: 32px;
height: 32px;
background-color: red;
}
.blue {
width: 32px;
height: 32px;
background-color: blue;
display: none;
}
.green {
width: 32px;
height: 32px;
background-color: green;
display: none;
}
.links {
display: inline-block;
margin-top: 50px;
}
<!DOCTYPE html>
<html>
<head>
<title>
titulo
</title>
<script src="jv/java.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="jv/jquery-3.5.1.js"></script>
<script type="text/javascript" src="jv/functions.js"></script>
</head>
<body>
<div class="red">
<div class="links">
<a href="#" id="red">red</a>
<a href="#" id="blue">blue</a>
<a href="#" id="green"> green</a>
</div>
</div>
<!-- red -->
<div class="blue">
<div class="links">
<a href="#" id="red">red</a>
<a href="#" id="blue">blue</a>
<a href="#" id="green"> green</a>
</div>
</div>
<!-- blue -->
<div class="green">
<div class="links">
<a href="#" id="red">red</a>
<a href="#" id="blue">blue</a>
<a href="#" id="green"> green</a>
</div>
<!-- green -->
</body>
</html>
You’re repeating the same
id
for several elements on the same page, and this is not advisable as you can see here: https://answall.com/questions/318255/por-que%C3%A9-considered-wrong-bad-repeat-an-id-in-html#:~:text=%C3%89%20wrong%20because%20est%C3%A1%20na,sense%20de%20realmente%20ser%20obrigat%C3%B3rio).– LeAndrade
You made a lot of sense, man. Thank you very much.
– lucas resende