Zak Ferris
Zak Ferris

Reputation: 47

How do I toggle my button text as well as toggle the div

I feel as though this fairly simple and probably a common problem, but i need to change the text back to it original state on a second click,

        $('#about').hide();     
      $('#about-btn').click(function(){         
            $('#about').toggle('down'),
             $(this).text('close');


        });

It stays with the words closed and I need it to switch about when the element is toggled.

Upvotes: 1

Views: 66

Answers (1)

VisioN
VisioN

Reputation: 145438

$("#about-btn").click(function() {
    if (this.innerHTML === "close") {
        this.innerHTML = "open";
        $("#about").slideUp();
    } else {
        this.innerHTML = "close";
        $("#about").slideDown();
    }
});

DEMO: http://jsfiddle.net/pX4QW/

Upvotes: 2

Related Questions