I'm still learning jQuery and I attempted to create a show/hide toggle button without relying on jQuery's toggle function. However, I can't seem to identify the issue in the code below.
Although the Hide button successfully hides the paragraph, the 'hide' functionality is working correctly. The class "show" is added while the class "hide" is removed, changing the button text accordingly. Upon inspecting with Dev Tools, this part seems to be functioning as expected. Yet, clicking the button again to show the paragraph doesn't work i.e the 'show' aspect.
$(document).ready(function() {
$(".hide").click(function() {
$(".content").hide();
$(this).addClass("show");
$(this).removeClass("hide");
$(this).text("Show");
});
$(".show").click(function() {
$(".content").show();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<p class="content">If you click on the "Hide" button, I will disappear.</p>
<button class="hide">Hide</button>