I am new to jQuery and currently practicing. I wrote a little piece of code to show and hide a navigation on click and change the text of the button when the navigation is opened and closed.
I am fresh in this area, therefore I would very much value getting some feedback about the code. For example, are there any ways to do it better, with less code or any other area of the matter? I would like a code review to learn and practice (the second if
is especially bothering me).
// Function Hide nav
function hideNav() {
$('nav').hide();
}
// Hide Nav
hideNav();
// Function Show Nav
function showNav() {
$('nav').show();
}
// Clickevent on Button
$('button').click(function() {
if($('nav').is(':hidden')){
// Show Nav on Clickevent
showNav();
// Change Text when Nav is showing
$(this).text('Close me');
}
else
hideNav();
// Change Text back when Nav is hiding
if($('nav').is(':hidden')){
$('button').text('Open me');
}
});