0
I have a problem with my code. I’m new to jQuery. He’s perfect, I was able to do almost everything I wanted, except for one thing I can’t fix: I can’t get him to clear if clicked again, getting like new.
Follow the code below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Pontos</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<style>
.rating {
overflow: hidden;
display: inline-block;
position: absolute;
font-size:18px;
color: #000000;
}
.rating-star {
padding: 0 1px;
margin: 0;
cursor: pointer;
display: block;
float: right;
}
.rating-star:after {
position: relative;
font-family: FontAwesome;
content:'\f1db';
}
.rating-star.checked ~ .rating-star:after,
.rating-star.checked:after {
content:'\f111';
}
.rating:hover .rating-star:after {content:'\f1db';}
.rating-star:hover ~ .rating-star:after,
.rating-star:hover:after {
content:'\f111' !important;
}
/* Just for the demo */
body {
margin: 20px;
}
</style>
</head>
<body>
<div class="rating">
<span class="rating-star" data-value="5"></span>
<span class="rating-star" data-value="4"></span>
<span class="rating-star" data-value="3"></span>
<span class="rating-star" data-value="2"></span>
<span class="rating-star" data-value="1"></span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$('.rating-star').click(function() {
$(this).parents('.rating').find('.rating-star').removeClass('checked');
$(this).addClass('checked');
});
</script>
</body>
</html>
Thank you, I tried at first as "radio", but unfortunately I could not get the result I wanted, I could not completely edit the radio buttons, I do not know if for lack of experience and knowledge. The buttons when marked at the time of printing they presented the natural image of them differing, completely from the design of the document. More anyway thank you very much, I will study more the buttons "radio".
– Erick Fontes