Answer the question
In order to leave comments, you need to log in
How can I make a favorites counter?
Good evening! help to make a counter when you click on the add to favorites button (so that when you click on your favorites, (1) (2) appears, etc. I hope for your help.
<div class="item-img">
<div class="item-img-line">
{% if _user %}
{% if row._faved %}<a href="#" class="fav faved" onclick="return fav({{row.id}});"><i class="icon-star"></i></a>
{% else %}<a href="#" class="fav" onclick="return fav({{row.id}});"><i class="icon-star-empty"></i></a>
{% endif %}
{% else %}
<a href="/signin/" class="fav"><i class="icon-star-empty"></i></a>
{% endif %}<span>№ {{row.id}}</span>
</div>
function fav(id)
{
if ($(".item[data-id="+id+"]").length) // in thumbnail
{
var el = $(".item[data-id="+id+"] .fav");
el.toggleClass('faved');
if (el.hasClass('faved')) el.html('<i class="icon-star"></i>');
else el.html('<i class="icon-star-empty"></i>');
}
if ($("#item[data-id="+id+"]").length) // in page
{
var el = $("#item[data-id="+id+"] .fav");
el.toggleClass('faved');
if (el.hasClass('faved')) el.html('Убрать из избранного<i class="icon-star"></i>');
else el.html('Добавить в избранное<i class="icon-star-empty"></i>');
}
$.ajax({url: "/auth", method: 'post', data: {'fav': id}, async: 'true', cache: 'false'});
return false;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question