In the two jsfiddles below, the $(document).on('ready', ....) call is made in the working sample via a callback for an AJAX execution (in the fiddle I use a setTimeout ti simulate a similar situation). In the non-working sample, the on ready is used as the closure for execution. Aside from the placement of the on ready, the code samples are identical.