programming4us
programming4us
WEBSITE

Sharepoint 2013 : Introducing jQuery for SharePoint developers (part 1) - Referencing jQuery, Understanding the global function, Understanding selector syntax

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

In the same way that developers can build and reuse their own JavaScript libraries, third parties have created JavaScript libraries that can simply be referenced and used in app development. Although there are many third-party libraries available on the Internet, one library, jQuery, is so popular that it has almost become synonymous with JavaScript itself.

The reason for the popularity of jQuery is that it does two very important things extremely well: it makes it easy to select elements from the document object model (DOM) and then perform operations on the selected elements. jQuery is so important that Microsoft has baked it into the app project template in Microsoft Visual Studio 2012. Therefore, SharePoint app developers must understand how to use the jQuery library. The following sections present a brief introduction to jQuery from the perspective of a SharePoint app developer. Readers who want complete coverage of the library should visit the jQuery website at www.jquery.com.

Referencing jQuery

To include any JavaScript library in an app, it must be referenced by using a script tag. The script tag refers to the location of the library so that it can be downloaded. In the Visual Studio app project template, the jQuery library is included as a file and referenced in the Default.aspx page, as shown in the following code:

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

Along with directly hosting the jQuery library in your app, you can also choose to use a content delivery network (CDN). A CDN hosts the jQuery library in the cloud so that it is always available. Referencing a CDN can improve performance of public-facing apps because the library is downloaded in parallel and cached. The same version of the library can then be used across several different apps. The following code shows how to reference the Microsoft CDN for jQuery:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.min.js" type="text/java
script">
</script>

Understanding the global function

The jQuery library is encapsulated in a single function named jQuery, which is known as the global function. Using the global function, you can easily select elements from the DOM, which is fundamental to any JavaScript solution. To select DOM elements, the global function is invoked and selector syntax is passed. The following code shows the traditional method of selecting elements in JavaScript by using the getElementById method, contrasted with the jQuery approach:

var elem1 = document.getElementById("displayDiv");
var elem2 = jQuery("#displayDiv");

In the preceding code, the jQuery selector syntax uses the hash sign to indicate that the selector corresponds to the ID of the desired element. You can simplify this code even further because the jQuery library uses the $ symbol as an alias for the global function. Therefore, the following code is equivalent:

var elem1 = document.getElementById("displayDiv");
var elem2 = $("#displayDiv");

Understanding selector syntax

At first, it might seem that selecting DOM elements by using jQuery is not that exciting. The power of jQuery, however, lies in the fact that the selector syntax is identical to that used in cascading style sheets (CSS). This means that you can use a rich, familiar selector syntax to reference any part of the DOM, which becomes a powerful and efficient way to manipulate the DOM elements. Table 1 shows common selection operations and how to accomplish them in jQuery.

Table 1. jQuery selector syntax

Operation

Example

Description

Select elements by type

$("p")

Selects all paragraph elements in the page

Select elements by ID

$("#container")

Selects the element whose ID is “container”

Select elements by class

$(".emphasis")

Selects all elements with a class attribute of “emphasis”

Select elements by type and ID

$("div#displayDiv")

Selects the <div> element whose ID is “displayDiv”

Select elements by ancestor and descendant

$("div#displayDiv p")

Select all paragraph elements within the <div> whose ID is “displayDiv”, regardless of where they are inside the div element

Select elements based on their parent

$("div#displayDiv > p")

Selects all paragraph elements that are children of the <div> whose ID is “displayDiv”

Select the first child of a parent

$("ul#displayList > li:first")

Selects the first list item element in the unordered list whose ID is “displayList”

Select the last child of a parent

$("ul#displayList > li:last")

Selects the last list item element in the unordered list whose ID is “displayList”

Select elements by attribute

$("input[name='firstName']")

Selects the input element whose name attribute is “firstName”

Once you understand the common selection operations, you can move ahead to combine them to create more sophisticated selectors. The jQuery library also supports a number of extensions that provide yet more capabilities.

Other  
  •  Sharepoint 2013 : Introducing JavaScript for SharePoint developers (part 3) - Creating custom libraries
  •  Sharepoint 2013 : Introducing JavaScript for SharePoint developers (part 2) - Understanding JavaScript functions, Understanding JavaScript closures, Understanding JavaScript prototypes
  •  Sharepoint 2013 : Introducing JavaScript for SharePoint developers (part 1) - Understanding JavaScript namespaces, Understanding JavaScript variables
  •  Sharepoint 2013 : List and library essentials - Creating and deleting lists
  •  Sharepoint 2013 : List and library essentials - Using your apps
  •  Sharepoint 2013 : Developing Applications Using Office Services - What’s New in Access Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - The New Machine Translation Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - Word Automation Services and the New PowerPoint Automation Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - What’s New in Excel Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - WOPI and the New Office Web Apps Server
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us