views:

292

answers:

2

HTML:

<a href="#">Show next element</a>
<div>content</div>

jQuery:

$('a').toggle(function () {
    $(this).next().show();
},
function () {
    $(this).next().hide();
});

How do I change the above jQuery so it also changes the "Show" in the link to "Hide" when the element is visible?

Thanks!

+1  A: 

Hasn't been tested...

$('a').toggle(function () {
    $(this).next().show();
    $(this).html("Hide next element");
},
function () {
    $(this).next().hide();
    $(this).html("Show next element");
});
JustChris
I figured it a sec ago. .text() is better, but thanks anyway!
Nimbuz
Great minds think alike :D
alex
@Nimbuz .text() only if you aren't including HTML.
alex
A: 
$('a').toggle(function () {

    $(this).next().show();
    $(this).html('Hide next element');
},
function () {
    $(this).next().hide();
    $(this).html('Show next element');
});
alex