Reputation: 127
This code is not clean. But it works
I need a code clean. Is there a way to convert this code into a clean code there?
var favIcon = $(obj).find('i').first();
if (favIcon.hasClass('fa-star')) {
favIcon.removeClass('fa-star');
favIcon.addClass('fa-star-o');
} else {
favIcon.removeClass('fa-star-o');
favIcon.addClass('fa-star');
}
Upvotes: 0
Views: 37
Reputation: 171669
Can use toggleClass()
and do it all in one line
$(obj).find('i').first().toggleClass('fa-star fa-star-o');
Upvotes: 2