How to check if jQuery library is loaded?

To check if jQuery library is loaded, use the following JavaScript code :


if (typeof jQuery != 'undefined') {

    alert("jQuery library is loaded!");

}else{

    alert("jQuery library is not found!");

}

Alternative?

In some blogs and forum mention about the following alternative code :


if (jQuery) {  

   alert("jQuery library is loaded!");

} else {

   alert("jQuery library is not found!");

}

However, this is not working, when the jQuery library is not loaded, this code will failed (jQuery is not define), and the alert message will never execute.

At last, the first jQuery checking method is always recommended.

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Angela Wyman
11 years ago

!!window.jQuery works also in the console- evaluates true it is loaded.

Dör Is
11 years ago

That was GOLDEN. Saved me many pulled hairs.

Tapash Kumar Datta
13 years ago

This will also help you.

DOM Load

Pawan Balapure
13 years ago

How to access parent jsp’s(the main jsp page) elements in the child jsp(the jsp page which is called from main jsp using object tag in html) in IE8?


$('#EcoOver').click(function (e) { 								
				$("#graphsDiv").html('<object id="EcoOverPage" type="text/html" style="width:100%;height:800px" data="/analytics-0.0.1/dashboard?pageId=1" ></object>')	 
				
				
				if(document.getElementById("loading") == null)
					{
						$("#graphsDiv").prepend("<div id='loading' >Please Wait...</div>");
					}
					else{
						$("#loading").show();
					} 
				 
				e.preventDefault();
			});
 

And,in the dashboard jsp page,I am doing ,

  $(document).ready(function() {
$(window.parent.document).find("#loading").hide(); });

This is working prefectly in chrome ,but not in IE8.When i tested it, it shows undefined for that div in dashboard page in IE8 after the dashboard page is rendered.And in chrome it’s showing correct value.

Please help me with it.
Thanks!

frnkeinstein
13 years ago
 $(document).ready(function(){
$("#myelement").click(function(){
alert("hallo")
});
});

is not working ,although jquery is working !