Trying to replace the stroke colour of a percentage circle for each item rendered in django project. So far, I have only managed to change the colour to red. I suspect this is because it is changing them all based on the first/last record(percentage) retrieved.
Is there a way to iterate through each item in jQuery so that the stroke colour will change per item?
jQuery:
$(function() {
var score = parseInt($("#percentage").text());
if (score <=40) {
$("path").css("color", "red")
} else if (score >=40) {
$("path").css("color", "green")
}
});
HTML:
{% extends "base.html" %}
{% load bootstrap_tags %}
{% load staticfiles %}
{% block head_js %}
<script src="{% static "js/percentage.js" %}"></script>
{% endblock %}
{% block content %}
{% for statistic in statistics %}
<div class="stat_img">
<img width="100%" src="/media/{{statistic.image}}">
</div>
<span id="percentage">{{statistic.percentage}}</span>
<div class="stat_ranking">
<span class="stat_title">{{statistic.title}} ({{statistic.year}})</span>
<br>
<svg viewbox="0 0 36 36" class="circular-chart">
<path class="circle" stroke-dasharray="{{statistic.percentage}}, 100"
d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"/>
<text x="50%" y="40%" text-anchor="middle" dy=".3em">{{statistic.percentage}}%</text>
<text class="blue" x="50%" y="55%" text-anchor="middle" dy=".3em">{{statistic.rating}}</text>
</svg>
</div>
<div class="statistics">
Genre: {{statistic.genre}} <br>
Box Office: ${{statistic.box_office}} <br>
Budget: ${{statistic.budget}}
</div>
<hr>
{% endfor %}
{% endblock %}