I've got this code on my page where the background color is working perfectly. However, I'm facing an issue with the li element - it doesn't update unless I refresh the page. For example, when the window size is smaller than 500px in width, the li elements are shown without needing to click anything.
function myFunction() {
if ($(window).width() < 500) {
$('body').css('background', 'black');
$("nav").click(function() {
$("li").toggle('slow');
});
} else {
$('body').css('background', 'blue');
$("li").show();
}
}