I need to do something very simple, and that I still only work halfway.
I have a <a href="#" class="favorites">Favorite</a> link, as you can see that it does not have a title attribute.
When the page is loaded, the script adds this title attribute:
<a href="#" class="favorites" title="Add to Favorites">Favorites</a>
When clicked, the class is checked, and then the title attribute must be changed, so the end result will be like this:
<a href="#" class="favorites checked" title="Item added to Favorites">Favorites</a>
I have this code, but although it changes the title attribute for a new one, when I click it again, the title attribute is not replaced, which is what I need:
$('.favorites').attr('title','Add to Favorites').click(function(){ $(this).toggleClass('checked').attr('title','Added to Favorites'); });
How and how can I "switch" attributes on click?
I created this DEMO to show this problem.
Thanks in advance.
source share