Recently, jQuery removed .toggle()
, and I don't know how to toggle text within a button. And yes, I've looked around this forum for an answer, but none were adequate.
Here is my code:
$("#show").click(function () {
if($(this).text() == "Show") {
$(this).text() == "Hide";
alert("Fill fields");
} else {
$(this).text() == "Show";
alert("Clear fields");
}
});
Explanation:
- When #show is clicked, execute anonymous function.
- if the text is "Show", change to "Hide"
- then, alert "Fill fields"
- Else, change text to "show"
- alert "Clear fields"