I've been struggling to update the text of a button after it's clicked, and I'm encountering an issue where it works in one part of my code but not in another.
Could someone please guide me on what might be missing in my code?
The first block of code is functional, but in the second snippet, the button text doesn't change upon clicking. Any assistance would be greatly appreciated! Below, I have included both sets of code snippets:
$(document).ready(function () {
$("#fold").click(function () {
$("#fold_p").fadeOut(function () {
$("#fold_p").text(($("#fold_p").text() == 'Hide') ? 'Show' : 'Hide').fadeIn();
})
})
});
....
</button>
$(document).ready(function () {
$("#fold").click(function () {
$("#fold_p").fadeOut(function () {
$("#fold_p").text(($("#fold_p").text() == 'Hide ') ? 'Show' : 'Hide').fadeIn();
})
})
});
<button class="button">
<div id="fold">
<span id="fold_p">Hide</span>
</div>
</button>
Thank you.