I am trying to create a function where clicking on a button will toggle the visibility of an element - hiding it when clicked once and showing it again when clicked again. I attempted to implement this using jQuery, but as I am new to Javascript, I can't figure out why it's not working.
$('#menuBtn').click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
$('.header-text').css({
'display': 'none'
});
} else {
$('.header-text').css({
'display': 'block'
});
}
$(this).data("clicks", !clicks);
});