Can use toggleClass()
and do it all in one line
$(obj).find('i').first().toggleClass('fa-star fa-star-o');
سؤال
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');
}
المحلول
Can use toggleClass()
and do it all in one line
$(obj).find('i').first().toggleClass('fa-star fa-star-o');