Example fiddle - http://jsfiddle.net/S6CwT/
CSS
#service_container {
display: none;
}
HTML
<a href="/services/update/8" id="view_service">View Service Record</a>
<div id="service_container">
Test
</div>
jQuery
jQuery.noConflict();
jQuery(function() {
// toggle visibility of service section
jQuery('#view_service').click(function() {
jQuery('#service_container').slideToggle('slow');
// toggle text
if (jQuery('#service_container').is(':visible')) {
jQuery('#view_service').text('Hide Service Record');
} else {
jQuery('#view_service').text('View Service Record');
}
return false
});
});
The bug is when clicking the link for the first time, the link text will change correctly to say Hide Service Record
but on subsequent clicks the text will not change to Show Service Record
when the div
is hidden and back to Hide Service Record
when the container is visible again.
Must be something silly I'm not spotting but can't see what I've done wrong.
I tried it the opposite way using is(:hidden)
but that behaves the same way.