Reputation: 3
I'm trying to make div .PA show when clicking on #toggle_pa and make it all save, but it won't work.
I don't know what to edit.
var $content0 = $('.PA');
if (localStorage.getItem('isVisible') === 'true') {
$content0.addClass('pa_visible');
$content0.removeClass('pa_content');
}
$('#toggle_PA').on('click', function() {
$content0.toggleClass('pa_visible');
$content0.addClass('pa_content');
localStorage.setItem('isVisible', $content0.hasClass('pa_visible'));
});
Full code: https://codepen.io/mSyx/pen/yWGxNZ
Here, clicking on #toggle_PA won't do anything. Any idea ?
Upvotes: 0
Views: 51
Reputation: 870
From the console of the codepen:
Uncaught ReferenceError: $ is not defined
Adding this code into the top of your html made the pen work and do as expected:
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
Upvotes: 1