hostias,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.rating{
box-sizing: border-box;
display: flex;
flex-direction: row-reverse;
justify-content: space-between;
width: 166px;
margin: 37px 0 0 0;
position: relative;}
.rating > div {
transition: 0.3s linear;
width: 21px;
height: 20px;
background: black;
cursor: pointer;}
.rating > div.active, .rating > div.active ~ *, .rating > div:hover, .rating > div:hover ~ *
{background: #1c9fe7;}
</style>
<script>
class Rating {
constructor(element, length = 5){
this.parent = element;
this.starLength = length;
this.stars = this.createElems(length);
this.parent.append(...this.stars);
this.parent.addEventListener("click", this.eventHandler.bind(this));
this.activeElem = this.stars[0];
}
createElems(length) {
let elems = Array.from({length}, () => document.createElement("div"));
return elems
}
eventHandler({target}){
if(this.stars.includes(target)){
this.activeElem.classList.remove("active");
this.activeElem = target;
this.activeElem.classList.add("active");
}
}
}
document.addEventListener("DOMContentLoaded", function() {
for (const element of document.querySelectorAll(".rating"))
new Rating(element, 5);
})
</script>
</head>
<body>
<div class="rating"></div>
<div class="rating"></div>
<div class="rating"></div>
<div class="rating"></div>
<div class="rating"></div>
</body>
</html>