chromedude chromedude -3 years ago 197
jQuery Question

Is there a way to check if jQuery has already been attached to an html page?

I have some jQuery which will be put on multiple different HTML pages which I have no clue whether they will have the jQuery Library attached or not. I would like to make it so that it does not load the library if it does already exist on the page so that it can be faster, but I can't figure out if there is a way to check for whether the library already is attached to the page.

Is there a way?

Answer Source

From HTML5 Boilerplate:

<script>window.jQuery || document.write('<script src="js/libs/jquery-1.6.4.min.js"><\/script>')</script>

Loads a local jQuery file if it hasn't already been loaded.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download