Body.scrollTop is deprecated in strict mode. Use "documentElement.scrollTop" if in strict mode and "body.scrollTop", only in quirks mode.

I get an error message:

body.scrollTop is deprecated in strict mode. Use "documentElement.scrollTop" if in strict mode and "body.scrollTop", only in quirks mode.

My code is:

$(document).ready(function(){ //Animates Scrolling to anchor function scrollToAnchor(aid){ var divTag = $("div[name='"+ aid +"']"); $('html,body').animate({scrollTop: divTag.offset().top},'slow'); } //If Checking out as guest, scroll to Shipping Information $("#ReadDescription").click(function() { scrollToAnchor('longdescreadmore'); }); }); 

How can I change my code to use this Element.ScrollTop document?

+6
source share
1 answer

Dugg Nabbit made a decision. The change

 $('html,body').animate({scrollTop: divTag.offset().top},'slow'); 

to

 $('html').animate({scrollTop: divTag.offset().top},'slow'); 

if you want to avoid the Chrome obsolescence warning. ( Why is body.scrollTop deprecated? )

This works because documentElement is an html node:

 $('html')[0] === document.documentElement //-> true $('body')[0] === document.body //-> true 

But your code is working now (albeit with a warning), and it will continue to work when Chrome removes the "bizarre" behavior. You do not have to change the code if you want to continue supporting browsers that use body.scrollTop to present scrolling viewports in standard mode (I think older Chrome and Safari).

+14
source

All Articles