Search code examples
meteorjquery-selectorsstartupiron-router

meteor loads script before DOM is ready - script is inside meteor.startup function


I'm trying to use document.querySelector("body") but i'm not getting any html elements back.

Why is that, the call to my script is inside meteor.startup?

I'm using iron router for my routing...

if(Meteor.isClient){

        Meteor.startup(function(){

            myScript()

        })

    }

Solution

  • Meteor.startup can fire only after DOMContentLoaded event. But IronRouter will probably render the content after that later.

    Try either using IronRouter's onAfterAction hook or template's rendered callback