This seems a little bit excessive, and was wondering if I can refactor this jQuery. I'm not sure if you need anymore information, or if it's possible just by looking at this script.
var getActiveState;
$(".modal-review__rating-order-wrap span").hover(function(){
$(this).parent().removeClass("is-active");
var thisStar = $(this).parent().find("[data-rating-value="+getActiveState+"]")
thisStar.removeClass("is-active");
}, function(){
var thisStar = $(this).parent().find("[data-rating-value="+getActiveState+"]")
if(getActiveState){
$(this).parent().addClass("is-active");
thisStar.addClass("is-active");
}
});
$(".modal-review__rating-order-wrap span").on("click",function(){
$(this).parent().addClass("is-active");
$(".modal-review__rating-order-wrap span").not(this).removeClass("is-active");
$(this).addClass("is-active");
getActiveState = $(this).data("rating-value");
return getActiveState;
});
This is applied to a 5 star system, wanted to show what the jQuery is affecting. When jQuery clicks on the star, it adds an .is-active
class to the span, and also to the wrap.
<div class="modal-review__rating-order-wrap">
<span class="icon-star" data-rating-value="1">
<svg>star 1</svg>
</span>
<span class="icon-star" data-rating-value="2">
<svg>star 2</svg>
</span>
<span class="icon-star" data-rating-value="3">
<svg>star 3</svg>
</span>
<span class="icon-star" data-rating-value="4">
<svg>star 4</svg>
</span>
<span class="icon-star" data-rating-value="5">
<svg>star 5</svg>
</span>
</div>