I'm trying to make a section that lists content on a query and ends with a link that changes it's name upon click. In this context, 'objetos' displays data from a class that I then turn to html.
{% for i in objetos %}
...
<a onclick="change()" id="{{i.id}}">Fav</a>
<script>
function change() {
var elem = document.getElementById("{{i.id}}");
if (elem.innerHTML == "Fav")
elem.innerHTML = "Unfav";
else
elem.innerHTML = 'Fav';
}
</script>
...
{% endfor %}
However the script seems to only load the last value of 'i', and so only the last link changes. Do I have to save it every time?