0
I have the following problem, when I click on a div the same should be with the background-color black and the color of the color that really is the background, until then it is working normally, but only when you click on a div only once, in the second click the div that is clicked does not lose the opacity, there would be some way to resolve this:
$(function() {
$('.grade:eq(1)').on('click', () => {
$('.grade:eq(1)').css({
'background-color': '#000',
'color': '#EC0080',
'filter': 'opacity(1)'
})
$('.grade:eq(0)').css({
'background-color': '#009ADE',
'color': '#FFF',
'filter': 'opacity(0.4)'
}).mouseenter(() => {
$('.grade:eq(0)').css('filter','opacity(1)')
}).mouseleave(() => {
$('.grade:eq(0)').css('filter','opacity(0.4)')
})
$('.grade:eq(2)').css({
'background-color': '#FFEA00',
'color': '#FFF',
'filter': 'opacity(0.4)'
}).mouseenter(() => {
$('.grade:eq(2)').css('filter','opacity(1)')
}).mouseleave(() => {
$('.grade:eq(2)').css('filter','opacity(0.4)')
})
})
$('.grade:eq(2)').on('click', () => {
$('.grade:eq(2)').css({
'background-color': '#000',
'color': '#FFEA00',
'filter': 'opacity(1)'
})
$('.grade:eq(1)').css({
'background-color': '#EC0080',
'color': '#FFF',
'filter': 'opacity(0.4)'
}).mouseenter(() => {
$('.grade:eq(1)').css('filter','opacity(1)')
}).mouseleave(() => {
$('.grade:eq(1)').css('filter','opacity(0.4)')
})
$('.grade:eq(0)').css({
'background-color': '#009ADE',
'color': '#FFF',
'filter': 'opacity(0.4)'
}).mouseenter(() => {
$('.grade:eq(0)').css('filter','opacity(1)')
}).mouseleave(() => {
$('.grade:eq(0)').css('filter','opacity(0.4)')
})
})
$('.grade:eq(0)').on('click', () => {
$('.grade:eq(0)').css({
'background-color': '#000',
'color': '#009ADE',
'filter': 'opacity(1)'
})
$('.grade:eq(1)').css({
'background-color': '#EC0080',
'color': '#FFF',
'filter': 'opacity(0.4)'
}).mouseenter(() => {
$('.grade:eq(1)').css('filter','opacity(1)')
}).mouseleave(() => {
$('.grade:eq(1)').css('filter','opacity(0.4)')
})
$('.grade:eq(2)').css({
'background-color': '#FFEA00',
'color': '#FFF',
'filter': 'opacity(0.4)'
}).mouseenter(() => {
$('.grade:eq(2)').css('filter','opacity(1)')
}).mouseleave(() => {
$('.grade:eq(2)').css('filter','opacity(0.4)')
})
})
})
.grades {
width: 350px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: baseline;
}
.grade {
width: 100px;
height: 100px;
margin: 5px;
color: #FFF;
font-size: 30px;
text-align: center;
line-height: 100px;
cursor: pointer;
}
.grade:nth-child(3n+1) {
background-color: #009ADE;
filter: opacity(0.4);
}
.grade:nth-child(3n+2) {
background-color: #EC0080;
filter: opacity(0.4);
}
.grade:nth-child(3n+3) {
background-color: #FFEA00;
filter: opacity(0.4);
}
.grade:nth-child(3n+1):hover {
filter: opacity(1);
}
.grade:nth-child(3n+2):hover {
filter: opacity(1);
}
.grade:nth-child(3n+3):hover {
filter: opacity(1);
}
.grade:nth-last-child(2) {
background-color: #000;
color: #EC0080;
filter: opacity(1);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="grades">
<div class="grade">21h</div>
<div class="grade">22h</div>
<div class="grade" id="escolhido">23h</div>
</div>
Hello Thiago, thanks for trying to help, your reply helped me in part, but I would need to leave the color of the text with the color of background and not only pink, but, I really appreciate the help!
– LeAndrade
Poxa Leandrade really, I ended up not paying attention to this detail of the text in your example, some time ago you must have been able to solve, but anyway I made some adjustments in CSS I believe that now this ok
– Thiago Costa
Good Thiago, thanks for the help, had kind of solved with js, but, I will use the way you did with Css same, thanks man!
– LeAndrade