Using views_embed_view and jquery
Drupal provides a specific way to add JS to a page, to ensure that it is run whenever content is loaded into the DOM. This way, it will run after the document is loaded, but also after AJAX operations.

They're called Drupal behaviors.