Im trying to call a method that will add or subtract 1 from a given span based on whether they already have it favorited or not (basically they favorite/unfavorite a resource and a little counter says “8 people favorited this” will be updated)
I want to write it short hand in the statement though rather than writing all kinds of if statements before the function, i thought there may be a fancy smarter way to do it.
this code obviously doesnt work but it should give you a gist of what im trying to say
updateFavoritesSpan( this, if ($(this).hasClass('starred')) 1 );
declaration:
function updateFavoritesSpan(element, isFavorite) {
$(element);
}
Just try this:
.hasClass()always return Boolean value, if found thentrueelsefalse.There is also another one called
.is()and it will use like: