HeadJS ready for both document and script

Posted by Yashua on Stack Overflow See other posts from Stack Overflow or by Yashua
Published on 2014-05-28T02:10:58Z Indexed on 2014/05/28 21:27 UTC
Read the original article Hit count: 187

Filed under:
|

Current code:

  head.ready(function() {
    console.log($('.thing a').val());
  });

It will sometimes fail with error that $ is not ready.

I have loaded jquuery earlier with the label 'jquery'. Neither of these work:

head.ready(document, function() {
  console.log($('.thing a').val());
});

head.ready('jquery', function() {
  console.log($('.thing a').val());
});

I would like to not do this if possible:

head.ready(document, function() {
  head.ready('jquery', function() {
    console.log($('.thing a').val());
  });
});

And also avoid refactoring current code to place that snippet at bottom of body though that I think may be the solution.

Is it possible with HeadJS to define a ready call() using head.ready(), that is not placed at the bottom, that will wait for both a labeled script and the DOM to be loaded?

UPDATE: the nested script doesn't actually work. I think the inner one erases/superseds the other :(

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about headjs