jQuery hide and show toggle div with plus and minus icon

前端 未结 7 2000
说谎
说谎 2020-12-05 02:59

I have the code working for the show and hide the div. How would I add two different icons as a sprite image for when the show and hide are active?

For

7条回答
  •  北海茫月
    2020-12-05 03:45

    Try something like this

    jQuery

    $('#toggle_icon').toggle(function() {
    
        $('#toggle_icon').text('-');
        $('#toggle_text').slideToggle();
    
    }, function() {
    
        $('#toggle_icon').text('+');
        $('#toggle_text').slideToggle();
    
    });
    

    HTML

    +
    
    
    

    DEMO

提交回复
热议问题