» posted on Friday, March 5th, 2010 at 2:49pm by Dan
How to Properly Test if jQuery is Loaded
I saw many people claiming you can test for the existence of jQuery like this:
1 2 3 4 5 | if (jQuery) { // jQuery exists, put code here } else { // jQuery not loaded, put code here } |
This is incorrect. It will work fine if jQuery is loaded, but if it's not loaded, javascript will throw an error and the code to execute if jQuery is not loaded will probably not be processed. The modification to fix this is simple:
1 2 3 4 5 | if (window.jQuery) { // jQuery exists, put code here } else { // jQuery not loaded, put code here } |
» Keywords
army
asp
buffer
cell phone
Code
css
domain tools
domain valuation
free flv player
freelance
free mp3 player
free mp4 player
google pagerank
haval
internet through cell phone
loading
md5
motorola razr
phone
PR
recordset
sha1
sha256
sha384
sha512
snefru
soldiers
voice mail
web flv player
website monitoring
Web Tools
![[del.icio.us]](http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png)
![[Reddit]](http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png)