admin管理员组文章数量:1334133
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?
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?
Share Improve this question edited Jan 22, 2021 at 1:37 amarinediary 5,4895 gold badges33 silver badges51 bronze badges asked Jan 21, 2021 at 13:18 Tomasz B.Tomasz B. 591 gold badge2 silver badges8 bronze badges3 Answers
Reset to default 2Cannot 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.
// A $( document ).ready() block.
$( document ).ready(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);
});
});
This ensures that the block of code is only run once the DOM is fully loaded.
you are getting this error because your javascript library is loading before your DOM is loaded. Make sure your DOM loads first.
The error shows that you are trying to read the property called nodeName
from null-valued variable that you think it was an object. Please check other parts of your code.
本文标签: javascriptUncaught TypeError Cannot read property 39nodeName39 of nullStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: Cannot read property 'nodeName' of null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742357750a2459754.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论