3
I have an icon of Font Awesome on which I am trying to get the element to be clicked, change the icon of fa fa-plus
for a fa fa-minus
and when clicking again, the icon goes back to the fa fa-plus
. How can I do that?
Here’s the code of what I’ve got so far:
$("#fa").click(function(){
var linhaClicada = $(this);
if (linhaClicada.removeClass("fa fa-plus")) {
linhaClicada.addClass("fa fa-minus");
//$("#excluir").hide();
}
else if(linhaClicada.removeClass("fa fa-minus")){
linhaClicada.addClass("fa fa-plus");
}
});
Note: I managed to get him to change the
fa fa-plus
to thefa fa-minus
, but I’m not getting him back into thefa fa-plus
when I click back.
The good thing about this code model is that you are not applying the click function directly to the element
i
. This way the click does not need to be exactly on the icon, but on the "context", that is, on the whole text (including the icon) that can/should perform the expected action. This improves the use of the element.– celsomtrindade
but here it is not going to always keep the same from a look at my code: '$('. badge pull-right'). click(Function(){ $(this). find('i'). toggleClass('fa-Minus fa-plus') });'
– Leonardo Costa
ignore my comment needed to put an id because with my class not caught now funfou obg friend
– Leonardo Costa