I have a link to hide/display some text:
<a href="javascript:void(0);" id="toggle_status_history">show/hide history<a/>
The corresponding JavaScript looks like this:
$(document).ready(function() {
$('#toggle_status_history').click(function() {
if ($('#status_history').is(":hidden")) {
$('#status_history').slideDown("fast");
} else {
$('#status_history').slideUp("fast");
}
});
It works great, but I'd like to toggle the hyperlink text as well. What do I need to do to modify the 'show/hide history' to show either 'hide history' (if it's currently displayed) or 'show history' if it's currently hidden? Something like this..?
$(document).ready(function() {
$('#toggle_status_history').click(function() {
if ($('#status_history').is(":hidden")) {
$('#status_history').slideDown("fast");
// SOMETHING HERE TO SET TEXT TO 'HIDE HISTORY'
} else {
$('#status_history').slideUp("fast");
// SOMETHING HERE TO SET TEXT TO 'SHOW HISTORY'
}
});
Disclaimer: I have less than an hour of experience with JQuery (and I haven't used JavaScript since the late-90s) - I'm just trying to modify a code sample for my site. I've looked at the API for the toggle() and replaceWith() functions but am not getting it to work. Googling and RTFM'ing hasn't helped me so far.
Many thanks in advance for your help!