最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change icon using jquery on click - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked Jan 27, 2015 at 14:15 RickyRicky 871 gold badge4 silver badges14 bronze badges 1
  • We need to see your HTML code to see what exactly you are trying to change. – Kelderic Commented Jan 27, 2015 at 14:21
Add a ment  | 

2 Answers 2

Reset to default 3

try

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

    });

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');


});
发布评论

评论列表(0)

  1. 暂无评论