Solution:
jQuery only need 1 function to make it work.
And your selector is not good, you need only $(‘body’) to target it.
$(document).ready(function() {
if ($('#collapseMenu').hasClass('show')) {
$('body').addClass('bodyblock');
console.log("Class bodyblock added to the body tag");
}
})
.bodyblock {
background-color: grey;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<div id="collapseMenu" class="show"></div>
</body>