I'm struggling with what is probably a very simple bit of jQuery
I have html like this:
<div class="star-rating" data-star-rating="5.0"></div>
<div class="star-rating" data-star-rating="2.0"></div>
I have some javascript which needs to do something based on the star rating of each of these elements and currently looks like this:
$('.star-rating').jRate({
startColor : '#ccc',
endColor : '#ccc',
readOnly : true,
rating : <value of data-star-rating>
});
I want to replace <value of data-star-rating>
with the value of the data attribute relating to the element currently being processed
I thought this would work $(this).data('starRating')
but it doesn't seem to
How can I access the value of the data attribute in this situation?
$(this).data('star-rating')
? – Descriptionconsole.log((".star-rating").data('star-rating'))
return? You dont even loop through elements, which one should it get ? 5.0 or 2.0 ? – Hydrology