$(document).ready(function() is not working

Viewed 163905

I am using Jquery for getting a json object from a solr server. When I run my html file with Tomcat it is runns fine but when I embed it with my project which is running on weblogic it gets this error: (debugging done through firebug)

$ is not defined
$(document).ready(function(){  

Why do I get this error when I embed it in my project?

This is the contents of my <head> tag, It is how I include jquery.js:

<head>
  <title>Search Result  </title>
  <style>
    img{ height: 150px; float: left; border: 3;}
    div{font-size:10pt; margin-right:150px;
    margin-left:150px; }
  </style>

  <script type="text/javascript" src="jquery-1.6.1.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){       //Error happens here, $ is not defined.

    });
  </script>
</head>
11 Answers

You can also write your jquery code in this function. document.addEventListener("DOMContentLoaded",function(),{ },false);

Set events after loading DOM Elements.

$(function () {
        $(document).on("click","selector",function (e) {
          alert("hi");

        });

    });
Related