Best Practices: jQuery for SharePoint development

Rule 1

Set jQuery in no conflict state

This requires you to use jQuery instead of $
For example, write
instead of

Rule 2

Use SharePoint's _spBodyOnLoadFunctionNames array instead of jQuery’s document ready function

SharePoint uses its own body onload function called _spBodyOnLoadFunctionNames which will collide with your document ready (run before or after).  If you are loading your JavaScript files through the elements.xml file (through a feature in Visual Studio), this can be particularly problematic with the order of how things load.

Instead, create a function with a custom name, and push the custom name into the _spBodyOnLoadFunctionNames array.  It’s wonderful and allows things to load in their proper order.

For example, write
function myCustomFunctionName() {
     // My custom functionality
instead of
$(document).ready(function() {
     // My custom functionality


Popular posts from this blog

The all new Movie Central

CRUD operations on SharePoint list using AngularJS

How to install nVidia Optimus driver