SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
jQuery Rescue Adventure
INTRODUCTION TO JQUERY INSIDE SHAREPOINT
Developer Track
Matt Jimison
About Me

   Name      Matt Jimison
 Location    Indianapolis, IN
    Work
    Blog     http://www.mattjimison.com/blog/
   Twitter   @mjimison
Presentation Goals
•   Introduce the jQuery Library
•   Discuss How to Incorporate jQuery with SharePoint
•   Review Highlights of the jQuery API
•   Demonstrate Using jQuery to Enhance UI
•   Empower Audience to Utilize jQuery for UI Enhancements
What is


    jQuery is a new kind of JavaScript Library.
jQuery Overview
• HTML Document Traversing
• Event Handling
• Animation
• AJAX
• Lightweight Footprint (~31KB)
• CSS3 Compliant (Supports Selectors)
• Cross-Browser (IE, Firefox, Safari, Opera, Chrome)
•   User Interface Library Built on Top of jQuery
•   Interactions (Drag, Drop, Resize, Select, Sort)
•   Widgets (Accordion, Autocomplete, Date, Tabs, Slider, etc…)
•   Effects (Animation, Show, Hide, Toggle)
•   Utilities
•   Touch-Optimized for Tablets and Smart Phones
•   Supports Multiple Devices
•   HTML5-based Interface
•   jQuery / jQueryUI Foundation
•   Lightweight




                                          7   | SharePoint Saturday Columbus 2011
jQuery and Microsoft
•   Microsoft contributes to the jQuery Project
•   Microsoft Product Support includes jQuery
•   jQuery ships with Visual Studio 2010+
•   Visual Studio Intellisense Support
Intellisense Demo
Downloading jQuery

• Local Copy
   ◦ Download from http://jquery.com/
   ◦ Current and Past Releases
• CDN (Content Delivery Network)
   ◦ Google
   ◦ Microsoft
   ◦ jQuery
CDN Considerations

• CDN Advantages
  ◦ Quicker Downloads
  ◦ More Parallel Downloads
  ◦ Increased Use of Cache
• CDN Disadvantages
  ◦ CDN Outages
  ◦ Loss of Internet Connection
• Fallback Option to Load Locally When CDN Fails
Usage Guidance
•   Use Minified Versions in Production
•   Consider Local Storage Over CDN for Intranets
•   Clearly Mark Your Version(s) of jQuery
•   Test Thoroughly When Upgrading Versions
•   Be as Unobtrusive as Possible
jQuery Conflict

• $ is an Alias for the jQuery function
• Many Libraries Use the $
  ◦ CmsSiteManager.js (SharePoint’s Asset Picker)
  ◦ Prototype.js
• Conflict Occurs When jQuery Overwrites Other
  Library’s function
• Solution: jQuery.NoConflict()
jQuery.noConflict()

• Removes jQuery’s use of the $ function
   ◦ Returns Control of $ to Other Libraries
   ◦ jQuery method can be used in place of $
   ◦ Alias jQuery By Capturing Return Value
      ◦ var jQ = jQuery.NoConflict();
   ◦ Pass $ to Ready Method For Scoped Usage
Adding jQuery to SharePoint
• MasterPage (Or Page Layout)
    ◦ Adds Unnecessary Overhead On Pages That Don’t Use jQuery (if any)
    ◦ Does not Touch Pages That Do Not Utilize Your MasterPage
• Content Editor WebPart (Or Custom WebPart)
    ◦ Becomes a Burden to Manage References and Consistent Use
    ◦ Use the Content Link Versus Inline Code
• Delegate Control
    ◦ Alternate Solution Exists in SharePoint 2010 (See next item)
• CustomAction (New in SharePoint 2010)
    ◦ Breaks Asset Picker without Additional Configuration
• Start.js
    ◦ jQuery Is Not Available At Page Load
Link jQuery to SharePoint Demo
jQuery API Browser
         Available Online:
         http://api.jquery.com/browser/







jQuery Selectors
• Derived from CSS 1 – 3
• Includes Additional jQuery Conventions
• Meta-Characters Need Escaped with 2 Backslashes ()
   ◦ !"#$%&'()*+,./:;<=>?@[]^`{|}~
• Common CSS Selector Support
   ◦ ID (#)
   ◦ Class (.)
   ◦ HTML (element)
Attribute Selectors
Description                                Selector
Equals Or Starts With Followed by Hyphen   [name|=“value”]
Contains Text                              [name*=“value”]
Contains Word Delimited by Spaces          [name~=“value”]
Ends With                                  [name$=“value”]
Starts With                                [name^=“value”]
Equals                                     [name=“value”]
Not Equals                                 [name!=“value”]
Has Attribute                              [name]
Multiple Attributes                        [name=“value”][name2=“value2”]
Basic and Child Filters
Description                        Selector
Currently Animating                :animated
Element at Given Index             :eq()
Even or Odd Elements in Results    :even, :odd
First or Last Element in Result    :first, :last
Currently Focused                  :focus
Greater Or Less than Given Index   :gt(), :lt()
Header Elements                    :header
Elements That Do Not Match         :not()
First or Last Child                :first-child, :last-child
Child at Given Index               :nth-child()
Only Children                      :only-child
Additional Selectors
Description                         Selector
Contains Content (case-sensitive)   :contains()
Empty Element                       :empty
Has An Element                      :has()
Parent Elements                     :parent
Selector Examples
Find ASP.Net Control Value (Works Around Control ID)
$("[id$='MyControl']").val()

Links With ‘Click here’ Inside Text
$(“a:contains(‘Click here’)”).css(“font-size”, “1.2em”)

Odd Rows on Table
$(“tr:odd”).addClass(“AlternateRow”)

SharePoint Field Control
var myField = $(“input[title=‘My Field’]”)
Manipulation
Description                              Method
Adding, Removing, Toggling CSS Classes   addClass(), removeClass(), toggleClass()
Adding Content                           .after(), .insertAfter(), .before(), .insertBefore(),
                                         .append(), .appendTo(), .prepend(),
                                         .prependTo()
Reading and Setting Attributes           .attr(“name”), .attr(“name”, “value”),
                                         .attr({“name1”: “value1”, “name2”: “value2”})

Reading and Setting CSS Styles           .css(“name”), .css(“name”, “value”),
                                         .css({“name1”: “value1”, “name2”: “value2”})

Reading and Setting Form Values          .val(), .val(“newvalue”)
Reading and Setting Text                 .text(), .text(“newvalue”)
Reading and Setting HTML                 .html(), .html(“<strong>newvalue</strong>”)
Wrapping Elements                        .wrap(), .wrapAll(), .wrapInner()
Removing Elements                        .remove(), .empty(), .detach(), .unwrap()
Manipulation Examples
Set SharePoint Field Control
$(“input[title=‘My Field’]”).val(“My New Value”);

Wrap Set of DIVs
$(“div.Item”).wrapAll(“<div class=‘ParentItem’ />”);

Toggle CSS Class
$(“div.Item”).toggleClass(“Highlighted”);

Set CSS
$(“#MyDiv”).css({“background”: “green”, “padding”: “5px”});
Traversal
Description                       Method
Loop through all items            .each()
Add Elements to Current Results   .add()
Filter Results                    .filter()
Filter Descendants                .find()
Map to a New Result               .map()
Children Selector                 .children()
Parent Selectors                  .parent(), .offsetParent(), .parentsUntil()
Sibling Selectors                 .siblings(), .next(), .prev(), .nextUntil(),
                                  .prevUntil()
Traversal Examples
Count Words in Each Paragraph
$("p").each(function(i) { $(this).append(" (" + $(this).text().split(' ').length + "
words)"); });


Wrap First Paragraph’s Siblings
$(“p:first”).siblings().wrapAll(“<div style=‘background:green’ />”);


Find Next Unordered Lists Following First Occurrence
$("ul:first").next("ul").css("background","yellow");
Events
Description                      Method
Generic Bind                     .bind(“method”, function() { })
Bind Event Once                  .one(“method”, function() { })
Bind Shortcuts                   .click(), .change(), .select(), .mouseover(),
                                 .mouseout(), .blur()
Hover (Mouseover and Mouseout)   .hover(function() { }, function() { })
Trigger Event                    .trigger(“method”)
Event Examples
Click Event On Paragraphs
$(“p”).click(function(event) { $(this).css(“background”, “yellow”)
});


Hover Events
$(“p”).hover(
       function(event) { $(this).addClass(“Highlight”); },
       function(event) { $(this).removeClass(“Highlight”); }
);
Developer Tools
Browser             Description

Chrome              Built-In Developer Tools (F12)



Firefox             Firebug (Separate Add-On)



Internet Explorer   Built-In Developer Tools (F12)
Console Demo
jQuery in Action

• Show / Hide Animations with Content Query
• Link Behaviors
• SharePoint Page Manipulation
• Announcements Slideshow
jQuery in Action Demo
Resources
• jQuery
• ScottGu: jQuery and Microsoft
• Jon Galloway: Using CDN Hosted jQuery with a
  Local Fall-back Copy
• Find External Links with jQuery
• jQuerify
• SlideDeck
Please Thank Our Sponsors

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Jquery
JqueryJquery
Jquery
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Jquery-overview
Jquery-overviewJquery-overview
Jquery-overview
 
J query
J queryJ query
J query
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
J query1
J query1J query1
J query1
 
Jquery
JqueryJquery
Jquery
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
SharePointfest Denver - A jQuery Primer for SharePoint
SharePointfest Denver -  A jQuery Primer for SharePointSharePointfest Denver -  A jQuery Primer for SharePoint
SharePointfest Denver - A jQuery Primer for SharePoint
 
jQuery
jQueryjQuery
jQuery
 
JQuery
JQueryJQuery
JQuery
 
Jquery 3
Jquery 3Jquery 3
Jquery 3
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jquery
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
J query introduction
J query introductionJ query introduction
J query introduction
 
Learn css3
Learn css3Learn css3
Learn css3
 

Destacado

Destacado (7)

Wcm sp-2013
Wcm sp-2013Wcm sp-2013
Wcm sp-2013
 
Improving Focus, Predictability, and Team Morale on Projects
Improving Focus, Predictability, and Team Morale on ProjectsImproving Focus, Predictability, and Team Morale on Projects
Improving Focus, Predictability, and Team Morale on Projects
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have known
 
Business Process Training, Tips and Tricks for Visio 2013
Business Process Training, Tips and Tricks for Visio 2013Business Process Training, Tips and Tricks for Visio 2013
Business Process Training, Tips and Tricks for Visio 2013
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 

Similar a jQuery Rescue Adventure

Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
Md. Ziaul Haq
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
Angel Ruiz
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
rsnarayanan
 

Similar a jQuery Rescue Adventure (20)

How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And Tricks
 
jQuery
jQueryjQuery
jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePoint
 
Web Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSWeb Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONS
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
JQuery Overview
JQuery OverviewJQuery Overview
JQuery Overview
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
Introduction to jQuery - The basics
Introduction to jQuery - The basicsIntroduction to jQuery - The basics
Introduction to jQuery - The basics
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentation
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

jQuery Rescue Adventure

  • 1. jQuery Rescue Adventure INTRODUCTION TO JQUERY INSIDE SHAREPOINT Developer Track Matt Jimison
  • 2. About Me Name Matt Jimison Location Indianapolis, IN Work Blog http://www.mattjimison.com/blog/ Twitter @mjimison
  • 3. Presentation Goals • Introduce the jQuery Library • Discuss How to Incorporate jQuery with SharePoint • Review Highlights of the jQuery API • Demonstrate Using jQuery to Enhance UI • Empower Audience to Utilize jQuery for UI Enhancements
  • 4. What is jQuery is a new kind of JavaScript Library.
  • 5. jQuery Overview • HTML Document Traversing • Event Handling • Animation • AJAX • Lightweight Footprint (~31KB) • CSS3 Compliant (Supports Selectors) • Cross-Browser (IE, Firefox, Safari, Opera, Chrome)
  • 6. User Interface Library Built on Top of jQuery • Interactions (Drag, Drop, Resize, Select, Sort) • Widgets (Accordion, Autocomplete, Date, Tabs, Slider, etc…) • Effects (Animation, Show, Hide, Toggle) • Utilities
  • 7. Touch-Optimized for Tablets and Smart Phones • Supports Multiple Devices • HTML5-based Interface • jQuery / jQueryUI Foundation • Lightweight 7 | SharePoint Saturday Columbus 2011
  • 8. jQuery and Microsoft • Microsoft contributes to the jQuery Project • Microsoft Product Support includes jQuery • jQuery ships with Visual Studio 2010+ • Visual Studio Intellisense Support
  • 10. Downloading jQuery • Local Copy ◦ Download from http://jquery.com/ ◦ Current and Past Releases • CDN (Content Delivery Network) ◦ Google ◦ Microsoft ◦ jQuery
  • 11. CDN Considerations • CDN Advantages ◦ Quicker Downloads ◦ More Parallel Downloads ◦ Increased Use of Cache • CDN Disadvantages ◦ CDN Outages ◦ Loss of Internet Connection • Fallback Option to Load Locally When CDN Fails
  • 12. Usage Guidance • Use Minified Versions in Production • Consider Local Storage Over CDN for Intranets • Clearly Mark Your Version(s) of jQuery • Test Thoroughly When Upgrading Versions • Be as Unobtrusive as Possible
  • 13. jQuery Conflict • $ is an Alias for the jQuery function • Many Libraries Use the $ ◦ CmsSiteManager.js (SharePoint’s Asset Picker) ◦ Prototype.js • Conflict Occurs When jQuery Overwrites Other Library’s function • Solution: jQuery.NoConflict()
  • 14. jQuery.noConflict() • Removes jQuery’s use of the $ function ◦ Returns Control of $ to Other Libraries ◦ jQuery method can be used in place of $ ◦ Alias jQuery By Capturing Return Value ◦ var jQ = jQuery.NoConflict(); ◦ Pass $ to Ready Method For Scoped Usage
  • 15. Adding jQuery to SharePoint • MasterPage (Or Page Layout) ◦ Adds Unnecessary Overhead On Pages That Don’t Use jQuery (if any) ◦ Does not Touch Pages That Do Not Utilize Your MasterPage • Content Editor WebPart (Or Custom WebPart) ◦ Becomes a Burden to Manage References and Consistent Use ◦ Use the Content Link Versus Inline Code • Delegate Control ◦ Alternate Solution Exists in SharePoint 2010 (See next item) • CustomAction (New in SharePoint 2010) ◦ Breaks Asset Picker without Additional Configuration • Start.js ◦ jQuery Is Not Available At Page Load
  • 16. Link jQuery to SharePoint Demo
  • 17. jQuery API Browser Available Online: http://api.jquery.com/browser/   
  • 18. jQuery Selectors • Derived from CSS 1 – 3 • Includes Additional jQuery Conventions • Meta-Characters Need Escaped with 2 Backslashes () ◦ !"#$%&'()*+,./:;<=>?@[]^`{|}~ • Common CSS Selector Support ◦ ID (#) ◦ Class (.) ◦ HTML (element)
  • 19. Attribute Selectors Description Selector Equals Or Starts With Followed by Hyphen [name|=“value”] Contains Text [name*=“value”] Contains Word Delimited by Spaces [name~=“value”] Ends With [name$=“value”] Starts With [name^=“value”] Equals [name=“value”] Not Equals [name!=“value”] Has Attribute [name] Multiple Attributes [name=“value”][name2=“value2”]
  • 20. Basic and Child Filters Description Selector Currently Animating :animated Element at Given Index :eq() Even or Odd Elements in Results :even, :odd First or Last Element in Result :first, :last Currently Focused :focus Greater Or Less than Given Index :gt(), :lt() Header Elements :header Elements That Do Not Match :not() First or Last Child :first-child, :last-child Child at Given Index :nth-child() Only Children :only-child
  • 21. Additional Selectors Description Selector Contains Content (case-sensitive) :contains() Empty Element :empty Has An Element :has() Parent Elements :parent
  • 22. Selector Examples Find ASP.Net Control Value (Works Around Control ID) $("[id$='MyControl']").val() Links With ‘Click here’ Inside Text $(“a:contains(‘Click here’)”).css(“font-size”, “1.2em”) Odd Rows on Table $(“tr:odd”).addClass(“AlternateRow”) SharePoint Field Control var myField = $(“input[title=‘My Field’]”)
  • 23. Manipulation Description Method Adding, Removing, Toggling CSS Classes addClass(), removeClass(), toggleClass() Adding Content .after(), .insertAfter(), .before(), .insertBefore(), .append(), .appendTo(), .prepend(), .prependTo() Reading and Setting Attributes .attr(“name”), .attr(“name”, “value”), .attr({“name1”: “value1”, “name2”: “value2”}) Reading and Setting CSS Styles .css(“name”), .css(“name”, “value”), .css({“name1”: “value1”, “name2”: “value2”}) Reading and Setting Form Values .val(), .val(“newvalue”) Reading and Setting Text .text(), .text(“newvalue”) Reading and Setting HTML .html(), .html(“<strong>newvalue</strong>”) Wrapping Elements .wrap(), .wrapAll(), .wrapInner() Removing Elements .remove(), .empty(), .detach(), .unwrap()
  • 24. Manipulation Examples Set SharePoint Field Control $(“input[title=‘My Field’]”).val(“My New Value”); Wrap Set of DIVs $(“div.Item”).wrapAll(“<div class=‘ParentItem’ />”); Toggle CSS Class $(“div.Item”).toggleClass(“Highlighted”); Set CSS $(“#MyDiv”).css({“background”: “green”, “padding”: “5px”});
  • 25. Traversal Description Method Loop through all items .each() Add Elements to Current Results .add() Filter Results .filter() Filter Descendants .find() Map to a New Result .map() Children Selector .children() Parent Selectors .parent(), .offsetParent(), .parentsUntil() Sibling Selectors .siblings(), .next(), .prev(), .nextUntil(), .prevUntil()
  • 26. Traversal Examples Count Words in Each Paragraph $("p").each(function(i) { $(this).append(" (" + $(this).text().split(' ').length + " words)"); }); Wrap First Paragraph’s Siblings $(“p:first”).siblings().wrapAll(“<div style=‘background:green’ />”); Find Next Unordered Lists Following First Occurrence $("ul:first").next("ul").css("background","yellow");
  • 27. Events Description Method Generic Bind .bind(“method”, function() { }) Bind Event Once .one(“method”, function() { }) Bind Shortcuts .click(), .change(), .select(), .mouseover(), .mouseout(), .blur() Hover (Mouseover and Mouseout) .hover(function() { }, function() { }) Trigger Event .trigger(“method”)
  • 28. Event Examples Click Event On Paragraphs $(“p”).click(function(event) { $(this).css(“background”, “yellow”) }); Hover Events $(“p”).hover( function(event) { $(this).addClass(“Highlight”); }, function(event) { $(this).removeClass(“Highlight”); } );
  • 29. Developer Tools Browser Description Chrome Built-In Developer Tools (F12) Firefox Firebug (Separate Add-On) Internet Explorer Built-In Developer Tools (F12)
  • 31. jQuery in Action • Show / Hide Animations with Content Query • Link Behaviors • SharePoint Page Manipulation • Announcements Slideshow
  • 33. Resources • jQuery • ScottGu: jQuery and Microsoft • Jon Galloway: Using CDN Hosted jQuery with a Local Fall-back Copy • Find External Links with jQuery • jQuerify • SlideDeck
  • 34. Please Thank Our Sponsors