Answer the question
In order to leave comments, you need to log in
How to check jquery connection?
Hello. I want to make a function with a call that checks if jquery is connected. If not connected, then connect, otherwise display alert. What am I doing wrong? How can I prevent jquery from being connected a second time when the function is called again?
function includejQuery() {
if (typeof jQuery === "undefined")
{
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "catalog/view/javascript/libs.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
}else if (typeof jQuery != "undefined") {
alert('Jquery уже загружен');
}
}
<script>
includejQuery(function(){
$('.block').remove();
});
</script>
<div class="block">Привет!</div>
Answer the question
In order to leave comments, you need to log in
It's simple:
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question