Main Tutorials

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.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Angela Wyman
9 years ago

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

Dör Is
9 years ago

That was GOLDEN. Saved me many pulled hairs.

Tapash Kumar Datta
11 years ago

This will also help you.

DOM Load

Pawan Balapure
11 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
11 years ago
 $(document).ready(function(){
$("#myelement").click(function(){
alert("hallo")
});
});

is not working ,although jquery is working !