I am attempting to check if my Jquery Library is loaded onto my HTML page. I am checking to see if it works, but something is not right. Here is what I have:
JavaScript
x
15
15
1
<html xmlns="http://www.w3.org/1999/xhtml">
2
<head>
3
<script type="text/javascript" src="/query-1.6.3.min.js"></script>
4
<script type="text/javascript">
5
$(document).ready(function(){
6
if (jQuery) {
7
// jQuery is loaded
8
alert("Yeah!");
9
} else {
10
// jQuery is not loaded
11
alert("Doesn't Work");
12
}
13
});
14
</script>
15
Advertisement
Answer
something is not right
Well, you are using jQuery to check for the presence of jQuery. If jQuery isn’t loaded then $()
won’t even run at all and your callback won’t execute, unless you’re using another library and that library happens to share the same $()
syntax.
Remove your $(document).ready()
(use something like window.onload
instead):
JavaScript
1
10
10
1
window.onload = function() {
2
if (window.jQuery) {
3
// jQuery is loaded
4
alert("Yeah!");
5
} else {
6
// jQuery is not loaded
7
alert("Doesn't Work");
8
}
9
}
10