Quick reminder to use noConflict() with jQuery in SharePoint

Posted Monday, August 3, 2009 9:36 AM by CoreyRoth

I’ve seen quite a few posts on jQuery and SharePoint lately. I haven’t seen too many people point this out (maybe I didn’t search well enough :) ), so I thought I would take a quick minute to remind you to use jQuery’s noConflict() method in SharePoint.  It appears somewhere in all of the magic JavaScript that powers SharePoint it too also makes use of the $ shortcut.  If you don’t simply having a reference to the jQuery script on a page can cause all number of things to break.  I have seen it break my own JavaScript as well as cause certain things not to display such as the Edit Web Part pane.  The next time you want to use jQuery with SharePoint, just add the following code and you should be good to go.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

  jQuery.noConflict();

</script>

Instead of using the $ to use jQuery methods you will have to use jQuery instead.  For example: $.get() would become jQuery.get().

Filed under: ,

Comments

# re: Quick reminder to use noConflict() with jQuery in SharePoint

Friday, November 21, 2014 8:44 AM by Mark Kamoski

Thanks for the tip. I was wondering, can one put this (the script tag you note in your article) in the head of the Master Page? Will that work? Please adivse.

# re: Quick reminder to use noConflict() with jQuery in SharePoint

Friday, November 21, 2014 9:41 AM by CoreyRoth

@Mark yes, that should work fine.

Leave a Comment

(required)
(required)
(optional)
(required)