开发者

jQuery in sharepoint returning Object Expected

开发者 https://www.devze.com 2022-12-24 14:07 出处:网络
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.

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 开发者_JAVA百科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.

Simon

0

精彩评论

暂无评论...
验证码 换一张
取 消