Opoe
Opoe

Reputation: 1387

jquery toggle with buttons two images?

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 toggles 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

Upvotes: 0

Views: 10401

Answers (2)

ChuckJHardy
ChuckJHardy

Reputation: 7066

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.

Upvotes: 6

BvdVen
BvdVen

Reputation: 2961

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"/>');
        });
});

Upvotes: 1

Related Questions