Is it possible to change between two fontawesome icons on hover?

后端 未结 6 1286
情书的邮戳
情书的邮戳 2020-12-05 00:52

I have an anchor tag with a font-awesome icon as follows


6条回答
  •  被撕碎了的回忆
    2020-12-05 01:13

    In jquery it would just be:

    $(document).ready(function () {
            $('.icon-unlock').hover(function () {
                $(this).addClass('icon-lock');
                $(this).removeClass('icon-unlock'); 
            }, function () {
                $(this).addClass('icon-unlock');
                $(this).removeClass('icon-lock');
            });
    
    
        });
    

    Here is a working jsfiddle of this.

    If you are using jquery ui then you can use .switchClass.

    An example of this would be:

    $(document).ready(function() {
       $(".icon-unlock").switchClass("icon-unlock", "icon-lock");
    });
    

    The api on .switchClass() is located here

提交回复
热议问题