bob
bob

Reputation: 81

How do I use jQuery with modernizr?

I would like to use modernizr to conditionally load polyfills. My code so far is pasted below.

At the moment the code I have successfully loads my support libraries. However, it although jQuery loads, it isn't being picked up by the browser.

If I include a script in the page that requires jQuery, I get the following errors in firebug:

So, How do I use jQuery with modernizr?

Also, how can I get my own scripts to run after jQuery (and whatever other support libraries I require, are loaded?

Modernizr.load([

{  // our polyfills first
  test : Modernizr.mq ,
  nope : ['../js/respond.js' ]
},

  'http://vframe/wp-content/themes/vframe/js/jquery-1.7.2.js',
  'http://vframe/wp-content/themes/vframe/js/jquery.form.js',
  'http://vframe/wp-content/themes/vframe/js/jquery.validate.min.js'


]) ;

Upvotes: 1

Views: 9191

Answers (2)

user2286550
user2286550

Reputation: 26

Modernizr.load function load the resources asynchronously but execute them in order. In this case response.js is being executed first than jQuery which means if you are using jQuery functions inside of your response.js it will not recognize it. As you know JavaScript interpreted line-by-line.

Upvotes: 0

XS_iceman
XS_iceman

Reputation: 171

I had a similar problem and solved it by loading jquery first then modernizr

Upvotes: 1

Related Questions