Ricky
Ricky

Reputation: 87

Change icon using jquery on click

Very new to jQuery, i'm trying to change the font icon class on click and display a drop down. currently it changes the icon and drops down, but when i want it to toggle back the text toggles but the icon stays the same. here is my code:

$(".answer1").hide();


$(".question1").on("click", function(){
    $(".answer1").toggle(300);
    $(this).find($(".fa")).removeClass('fa-plus').addClass('fa-minus');


});

any advice?

Upvotes: 0

Views: 14209

Answers (2)

Balachandran
Balachandran

Reputation: 9637

try

   $(".question1").on("click", function(){
        $(".answer1").toggle(300);
        $(this).find($(".fa")).toggleClass('fa-plus fa-minus');

    });

Upvotes: 3

Ricky
Ricky

Reputation: 87

Seconds after posting i tried something and it worked, would this be ok to use? it does what i want it to:

$(".question1").on("click", function(){
    $(".answer1").toggle(300);
    $(this).find($(".fa")).toggleClass('fa-plus').toggleClass('fa-minus');


});

Upvotes: 2

Related Questions