简体   繁体   English

单击时使用jQuery更改图标

[英]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. 对jQuery非常新,我试图在单击时更改字体图标类并显示一个下拉列表。 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? 有什么建议吗?

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


});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM