Aos: Everything working, but console still showing "Uncaught TypeError: Cannot read property 'setAttribute' of null"

Created on 25 Sep 2016  路  2Comments  路  Source: michalsnik/aos

I looked at #42 but it's not quite what I'm dealing with here. I have the actual script loaded in the head, but I initialize it at the end right before . And it works, but when I open up DevTools I still see the error. I'm using this for my Rails application, so I don't know if that has anything to do with it. Any ideas on how I can get that error to go away? Or since I got it working, should I not worry about it?

question waiting for response

Most helpful comment

It happens because no attribute has been found due to the bad timing!
I had this happening because I called AOS.init before the whole DOM has been loaded. The solution is to call AOS.init() only within
$(document).ready(function(){
AOS.init({duration: 1000});
});

All 2 comments

Hi @marcnjaramillo,

Loading script in HEAD should work just fine so you can leave it there. It looks like in the place where you initialize AOS there is no body in DOM yet and it throws an error on this line of code:

document.querySelector('body').setAttribute('data-aos-easing', options.easing);

Can you confirm that document.querySelector('body') right before AOS.init() doesn't return null? If you initialize AOS in place where you can access body in DOM - it should not throw any error.

It happens because no attribute has been found due to the bad timing!
I had this happening because I called AOS.init before the whole DOM has been loaded. The solution is to call AOS.init() only within
$(document).ready(function(){
AOS.init({duration: 1000});
});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simmonsr picture simmonsr  路  4Comments

junaidfarooqui picture junaidfarooqui  路  3Comments

webdevnerdstuff picture webdevnerdstuff  路  3Comments

luminawastaken picture luminawastaken  路  3Comments

AndTheGodsMadeLove picture AndTheGodsMadeLove  路  3Comments