开发者

jquery toggle with buttons two images?

开发者 https://www.devze.com 2023-02-05 10:16 出处:网络
To toggle hide/show, i used this code; togglebtn.click(function() { var that = this; $(\'.togglecontainer\').toggle(500, function(){

To toggle hide/show, i used this code;

togglebtn.click(function() {
    var that = this;
    $('.togglecontainer').toggle(500, function(){
        var txt = $(that).html();
        $(that).html((txt == 'Show less') ? 'Show more' : 'Show less');
    });
});
togglebtn.trigger("click");

But it tog开发者_如何学Cgles text inside one button. I want two buttons, with two diffrent img src's let's say images/show.png and images/hide.png

Thanks in advance


Have a look at this Tutorial - jQuery Image Swap Using Click - This may be what you are trying to achieve. Let us know how you get on.


I'm not really sure this is wat you mean but: You could use the Id's of the buttons

togglebtn.click(function(){
            var btn = this;
        $('.togglecontainer').toggle(500, function(){
            var txt = $(btn).html();
            $(btn).html((txt == 'Show less') ? 'Show more' : 'Show less');
            $("#btn2_Id").html((txt == 'Show less') ? '<img src="http://yourdomain.com/images/hide.png"/>' : '<img src="http://yourdomain.com/images/show.png"/>');
        });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消