I have a code:
(function($) {
$(window).scroll(function() {
if ($(this).scrollTop() >= 50) { // If page is scrolled more than 50px
$('#return-to-top').fadeIn(200); // Fade in the arrow
} else {
$('#return-to-top').fadeOut(200); // Else fade out the arrow
}
});
$('#return-to-top').click(function() { // When arrow is clicked
$('body,html').animate({
scrollTop : 0 // Scroll to top of body
}, 500);
});
})(jQuery);
In Chrome, I'll truncate the page down. Then I get an error in the console.
> Uncaught TypeError: Cannot read property 'nodeName' of null
>> at _e (index.js:63)
>>> at MutationObserver.<anonymous> (index.js:63)
Page in Wordpress. Anyone can help?
Cannot read property 'nodeName' of null suggests that something you are trying to access from jQuery is not available at the time the script is trying to access it.
Without seeing the rest of the code it would be hard to tell what is missing, but as a starting point, ensure that your jQuery function is surrounded by document on ready function.
This ensures that the block of code is only run once the DOM is fully loaded.