Reverting the reorder above may allow you to use 'domready' event here.