Tutorial :jQuery in sharepoint returning Object Expected


When I add jquery to sharepoint 2007 (MOSS) and try and use it on a page no matter what I write on the client i get an "object expected" at the line/column where the "$" appears.

I have used fiddler to check that the client is downloading the query JS (which it is)

But its like its being ignore and therefor eth "$" is not understood. Searching google everybody is saying its the selector not finding the elements but see code below I do not see how it can not find my very simple example.

In master page in header

<script type="text/javascript" src="jquery.min.js"></script>  

version 1.4.2

On a page

  <a href="javascript:abc();">Testing</a>  <script>  function abc(){          $("#simon").css("border","3px solid red");      }  </script>  <div id="simon">  


Put your JS right at the bottom of your page and rewrite it as:

        $(function() {          function abc() {              $("#simon").css("border", "3px solid red");          }      });  


It might be using jQuery in noConflict mode, so try using:

jQuery("#simon").css("border","3px solid red");  


I'd change to this overall:

<span id="testLink">Testing</span>  <div id="simon">Content Here</div>  <script type="text/javascript">    $(function() {      $("#testLink").click(function() {        $("#simon").css("border","3px solid red");      });    }  </script>  

Best to attach your events as handlers instead of in-line, and you need to this on document.ready, which $(function() { }); wrapping does. This also lets you do all this in an included javascript file instead of including it in the page every time.


Problem seemed to be that I was using the jquery from Googles CDN, downloaded from jquerry.com and now works.

Thanks everybody for your answers, very helpful.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »