jQuery click function with localStorage not working
问题 I want to set a theme preference cookie for a link function. Here's how the HTML of the element looks like: <li class="menu-item theme-item"> <a href="javascript:void()" class="btn" aria-pressed="false">Theme Toggle</a> </li> And here's how the jQuery function for this element is set: $('.theme-item .btn').on('click', function(e) { e.preventDefault(); $(this).attr('aria-pressed', $(this).attr('aria-pressed') === 'false' ? 'true' : 'false'); $('html').attr('data-theme', $('html').attr('data