-6
Friends, good afternoon. I’ve been racking my brain for 2 days because of this:
I have 2 radio button that has an icon and a text: when I select one, the icon is replaced by a lighter icon (white), as well as the color of the letter (the first by JS, the second by CSS).
Well, when I select the other radio button, I wanted the icon to return to its original color, that is, to red again.
What I did is here: https://jsfiddle.net/guilhermelirio85/8bz41ehr/
$('.radio_item').click('label', changeImage);
function changeImage(evt) {
var imageId = evt.target.id;
switch (imageId) {
case 'radio1':
$('#img-radio1').attr("src", "http://www.blocodochapolin.com.br/michel/icon_acessorios.png");
break;
case 'radio2':
$('#img-radio2').attr("src", "http://www.blocodochapolin.com.br/michel/icon_agro.png");
}
}
.radio_item {
display: none !important;
}
.label_item {
background: url("http://www.blocodochapolin.com.br/michel/icon_acessorios.png")
}
.radio_item:checked+label {
background-color: red;
border-radius: 50px;
padding-left: 5px;
padding-right: 5px;
color: white;
height: 27px
}
label {
cursor: pointer;
}
img {
margin-bottom: -10px
}
span {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--RADIO 1-->
<input type="radio" class="radio_item" value="" name="item" id="radio1">
<label class="label_item" for="radio1"> <img id="img-radio1" width='30' height="30" src="http://www.blocodochapolin.com.br/michel/icon_acessorios2.png" /> <span>Acessórios</span></label>
<!--RADIO 2-->
<input type="radio" class="radio_item" value="" name="item" id="radio2">
<label class="label_item" for="radio2"> <img id="img-radio2" width='30' height="30" src="http://www.blocodochapolin.com.br/michel/icon_agro2.png" /> Agro</label>
How could I?
I don’t understand the question.
– Taffarel Xavier
@Taffarel Xavier sorry. I improved the question, see if it became clearer.
– Guilherme Lirio
I think that by the evaluation the option to answer this question is disabled, but I understood the question. I would recommend you to do completely by CSS, here is jsfiddle edited this way: https://jsfiddle.net/renatomariscal/soz5ymwd/
– Renato
That would be @Renato. Thank you very much for your help and sorry for the poorly prepared question. I will improve next!
– Guilherme Lirio
@Renato can answer now, thank you!
– Guilherme Lirio