Does anyone know how to check if jquery has been loaded (with javascript) then load it if it hasnt been loaded.
something like
if(!jQuery) { //load jquery file }
Basically, the most reliable way to check if jQuery has been loaded is to check typeof jQuery — it will return "function" if jQuery was already loaded on the page, or "undefined" if jQuery hasn't been loaded yet.
You can check the document. readyState property. From MDN: Returns "loading" while the document is loading, "interactive" once it is finished parsing but still loading sub-resources, and "complete" once it has loaded.
Maybe something like this:
<script> if(!window.jQuery) { var script = document.createElement('script'); script.type = "text/javascript"; script.src = "path/to/jQuery"; document.getElementsByTagName('head')[0].appendChild(script); } </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With