SlideShare a Scribd company logo
1 of 20
jQuery Jon Erickson @jonerickson http://jonerickson.me/ http://jonerickson.me/jquery/
What is jQuery? JavaScript framework that makes your life easier Selectors & Chaining DOM Traversing DOM Manipulation Event Handling Animations/Effects AJAX Built-in Utilities Extensible Tons of plug-ins built by the community for our use
Why jQuery? I’m not an expert at JavaScript The people who created jQuery are! Do not need to worry about cross-browser issues (all abstracted) Light Weight (19 kb compressed) DRY – Simple plug-in model allows for code reuse Animations/Effects are simple Community support is growing rapidly Microsoft adoption (included in MVC template) Tutorials, plug-ins, etc. Client-side scripting is fun with jQuery and breathes some new life into your applications Focus more on the code that solves your problem Amazon, BBC, Dell, Google, IBM, NBC, Netflix, Twitter
Sample jQuery Our DOM Include jQuery The ‘ready event’ – Binds a function to be executed whenever the DOM is ready Select the ‘toggleContent’ DOM element and bind a click event handler to it. Select the ‘content’ DOM element and set the text to ‘Hello World!’ Prevent the default behavior of the anchor tag by returning false
Dollar Function $(); JavaScript identifiers can start with $ The jQuery framework automatically assigns ‘$’ to the ‘jQuery’ function $ === jQuerytrue $(selector) is same as jQuery(selector) Can use utility function to unassign $ $.noConflict(); $ === jQuery;	false Can reassign jQuery to another variable $j = $.noConflict();	 $j === jQuery;	true $j === $;		false $ === jQuery;	false
Document Ready Event $(document).ready(fn); The bound function will be called the instant the DOM is ready to be read and manipulated. As many as you want on the page. Executed in the order they were added. There is a shortcut: $(fn);
Selectors CSS3 Selectors
Filters $(‘div:empty’), $(‘:empty’), $(‘div:not(:empty)’) Custom Filter Used
Chaining Most jQuery methods return another jQuery object (usually the same collection), which means you can chain method calls together with a fluent like syntax Some methods that stop a chain, these methods return a value from the jQuery object 	.css(name), .text(), .html(), .val(), .height(), .width(), .is(‘:visible’) Some methods will return a different jQuery collection, you can revert to the previous collection by calling .end();
Attributes & Classes Getters & Setters for attr, html, text, val Getter (returns String – breaks chain) var text = $(‘#myDiv’).text(); Setter (returns jQuery) $(‘#myDiv’).text(‘Hello World!’); text() escapes html() val() used with inputs attr() can take JSON Add, Remove for Attributes & Classes .removeAttr(‘someAttr’); .addClass(‘someClass’); .removeClass(‘someClass’); .toggleClass(‘someClass’);
Traversing Family parent, parents, siblings, children Proximity closest, next, prev, nextAll, prevAll Searching find
Events .bind(type, data, fn) ,[object Object],.one(type, data, fn) ,[object Object],.trigger(event, data) ,[object Object],.unbind(type, fn) ,[object Object],.live(type, fn) ,[object Object],.die(type, fn) ,[object Object],.hover(fnOver, fnOut) ,[object Object],.toggle(fn1, fn2, fn3, fnN, …) ,[object Object],[object Object]
Manipulation Inserting Inside append, prepend appendTo, prependTo Inserting Outside after, before insertAfter, insertBefore Inserting Around wrapInner wrap wrapAll Replacing replaceWith, replaceAll Removing empty, remove Copying clone
Effects Basics show, hide, toggle Sliding slideUp, slideDown, slideToggle Fading fadeIn, fadeOut, fadeTo (opacity 0-1) Custom animate, stop
Plug-ins Extremely Simple – Promotes code reuse and DRY principle $.fn.MyPlugin = function(params) {}; Return a jQuery object to prevent from “breaking the chain” Unless you are returning a specific value Best Practice is to wrap the plug-in declaration within an anonymous JavaScript function in order to prevent collisions with the use of $ Within the plug-in ‘this’ refers to the jQuery object
AJAX Helpers load, get, getJSON, getScript, post (all use $.ajax behind the scenes) $.ajaxSetup(options) can be used to globally set the default options for all AJAX request. You can still override these within each AJAX request object. Local Events – subscribed to within AJAX request object Global Events – broadcast to all elements in the DOM Can be disabled within the AJAX request object’s ‘global’ property .bind(‘ajaxStart’, fn) or .ajaxStart(fn) G | ajaxStart L | beforeSend G | ajaxSend L | success G | ajaxSuccess L | error G | ajaxError L | complete G | ajaxComplete G | ajaxStop
Utility Functions Array and Object Operations $.each(object, callback) – Callback function will run for each item in the object. The each method is meant to be an immutable iterator and returns the original array. $.map(array, callback) – Callback function will run for each item in the array. The map method can be used as an iterator, but is designed to be used for manipulation of the supplied array and returns a new array. $.merge(first, second) – Merges the second array into the first array. $.unique(array) – Removes duplicate elements (only works on arrays of DOM elements). $.extend(object) – Add functions into the jQuery namespace. $.extend(deep, target, object1, objectN) – Merge values from objects 1 to N into target object. Deep is an optional boolean that if true, tells jQuery to do a deep copy. $.grep(array, callback, invert) – Iterates through array, and returns a new array with values from the original array that satisfy the criteria specified in the callback. $.inArray(value, array) – Gets the index of the value in the array (-1 if not found). String Operations $.trim(str) – Removes whitespace from the given string. Test Operations $.isArray(obj) – Determines if the object is an array. $.isFunction(obj) – Determines if the object is a function.
jQuery Data Can store data on one or more jQuery elements .data(name, value) value is an object Retrieves data from the first element in the jQuery object .data(name)
Resources jQuery Main http://jquery.com http://docs.jquery.com/Downloading_jQuery jQuery API Documentation http://api.jquery.com http://docs.jquery.com jQuery UI http://jqueryui.com http://jqueryui.com/themeroller/ jQuery Blog http://blog.jquery.com/ Around The Web http://stackoverflow.com http://www.nettuts.com http://www.smashingmagazine.com Tools Visual Studio JavaScript Intellisense Support (KB958502) http://getfirebug.com/ (Firebug Firefox Plug-in) http://jsbin.com/  (JS Bin - Collaborative JavaScript Debugging) Twitter @jquery, @jqueryui, @jresig, @rem, @codylindley , @reybango, @elijahmanor, @jamespadolsey, @brandonaaron, @malsup, @pbakaus, @rworth
jQuery

More Related Content

What's hot

JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashBret Little
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreNicolas Carlo
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4sotlsoc
 
Wicket KT part 2
Wicket KT part 2Wicket KT part 2
Wicket KT part 2stuq
 
jQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheetjQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheetJiby John
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うbpstudy
 

What's hot (9)

JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Wicket KT part 2
Wicket KT part 2Wicket KT part 2
Wicket KT part 2
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Introduction to-scala
Introduction to-scalaIntroduction to-scala
Introduction to-scala
 
jQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheetjQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheet
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 

Viewers also liked

Viewers also liked (6)

Kaleehume 3222
Kaleehume 3222Kaleehume 3222
Kaleehume 3222
 
Livejournal
LivejournalLivejournal
Livejournal
 
Sawwan desire 1_3
Sawwan desire 1_3Sawwan desire 1_3
Sawwan desire 1_3
 
Sawwan desire 1-3
Sawwan desire 1-3Sawwan desire 1-3
Sawwan desire 1-3
 
Livejournal
LivejournalLivejournal
Livejournal
 
Mueller n 1_22_2-1
Mueller n 1_22_2-1Mueller n 1_22_2-1
Mueller n 1_22_2-1
 

Similar to jQuery

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 Libraryrsnarayanan
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperManoj Bhuva
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New EvolutionAllan Huang
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue AdventureAllegient
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxazz71
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETJames Johnson
 
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxMicrosoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxtutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfRAVALCHIRAG1
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 

Similar to jQuery (20)

jQuery
jQueryjQuery
jQuery
 
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
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java Developer
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New Evolution
 
jQuery
jQueryjQuery
jQuery
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxMicrosoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
jQuery-1-Ajax
jQuery-1-AjaxjQuery-1-Ajax
jQuery-1-Ajax
 
jQuery-1-Ajax
jQuery-1-AjaxjQuery-1-Ajax
jQuery-1-Ajax
 
droidparts
droidpartsdroidparts
droidparts
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
 
J query training
J query trainingJ query training
J query training
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Ruby tricks2
Ruby tricks2Ruby tricks2
Ruby tricks2
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

jQuery

  • 1. jQuery Jon Erickson @jonerickson http://jonerickson.me/ http://jonerickson.me/jquery/
  • 2. What is jQuery? JavaScript framework that makes your life easier Selectors & Chaining DOM Traversing DOM Manipulation Event Handling Animations/Effects AJAX Built-in Utilities Extensible Tons of plug-ins built by the community for our use
  • 3. Why jQuery? I’m not an expert at JavaScript The people who created jQuery are! Do not need to worry about cross-browser issues (all abstracted) Light Weight (19 kb compressed) DRY – Simple plug-in model allows for code reuse Animations/Effects are simple Community support is growing rapidly Microsoft adoption (included in MVC template) Tutorials, plug-ins, etc. Client-side scripting is fun with jQuery and breathes some new life into your applications Focus more on the code that solves your problem Amazon, BBC, Dell, Google, IBM, NBC, Netflix, Twitter
  • 4. Sample jQuery Our DOM Include jQuery The ‘ready event’ – Binds a function to be executed whenever the DOM is ready Select the ‘toggleContent’ DOM element and bind a click event handler to it. Select the ‘content’ DOM element and set the text to ‘Hello World!’ Prevent the default behavior of the anchor tag by returning false
  • 5. Dollar Function $(); JavaScript identifiers can start with $ The jQuery framework automatically assigns ‘$’ to the ‘jQuery’ function $ === jQuerytrue $(selector) is same as jQuery(selector) Can use utility function to unassign $ $.noConflict(); $ === jQuery; false Can reassign jQuery to another variable $j = $.noConflict(); $j === jQuery; true $j === $; false $ === jQuery; false
  • 6. Document Ready Event $(document).ready(fn); The bound function will be called the instant the DOM is ready to be read and manipulated. As many as you want on the page. Executed in the order they were added. There is a shortcut: $(fn);
  • 8. Filters $(‘div:empty’), $(‘:empty’), $(‘div:not(:empty)’) Custom Filter Used
  • 9. Chaining Most jQuery methods return another jQuery object (usually the same collection), which means you can chain method calls together with a fluent like syntax Some methods that stop a chain, these methods return a value from the jQuery object .css(name), .text(), .html(), .val(), .height(), .width(), .is(‘:visible’) Some methods will return a different jQuery collection, you can revert to the previous collection by calling .end();
  • 10. Attributes & Classes Getters & Setters for attr, html, text, val Getter (returns String – breaks chain) var text = $(‘#myDiv’).text(); Setter (returns jQuery) $(‘#myDiv’).text(‘Hello World!’); text() escapes html() val() used with inputs attr() can take JSON Add, Remove for Attributes & Classes .removeAttr(‘someAttr’); .addClass(‘someClass’); .removeClass(‘someClass’); .toggleClass(‘someClass’);
  • 11. Traversing Family parent, parents, siblings, children Proximity closest, next, prev, nextAll, prevAll Searching find
  • 12.
  • 13. Manipulation Inserting Inside append, prepend appendTo, prependTo Inserting Outside after, before insertAfter, insertBefore Inserting Around wrapInner wrap wrapAll Replacing replaceWith, replaceAll Removing empty, remove Copying clone
  • 14. Effects Basics show, hide, toggle Sliding slideUp, slideDown, slideToggle Fading fadeIn, fadeOut, fadeTo (opacity 0-1) Custom animate, stop
  • 15. Plug-ins Extremely Simple – Promotes code reuse and DRY principle $.fn.MyPlugin = function(params) {}; Return a jQuery object to prevent from “breaking the chain” Unless you are returning a specific value Best Practice is to wrap the plug-in declaration within an anonymous JavaScript function in order to prevent collisions with the use of $ Within the plug-in ‘this’ refers to the jQuery object
  • 16. AJAX Helpers load, get, getJSON, getScript, post (all use $.ajax behind the scenes) $.ajaxSetup(options) can be used to globally set the default options for all AJAX request. You can still override these within each AJAX request object. Local Events – subscribed to within AJAX request object Global Events – broadcast to all elements in the DOM Can be disabled within the AJAX request object’s ‘global’ property .bind(‘ajaxStart’, fn) or .ajaxStart(fn) G | ajaxStart L | beforeSend G | ajaxSend L | success G | ajaxSuccess L | error G | ajaxError L | complete G | ajaxComplete G | ajaxStop
  • 17. Utility Functions Array and Object Operations $.each(object, callback) – Callback function will run for each item in the object. The each method is meant to be an immutable iterator and returns the original array. $.map(array, callback) – Callback function will run for each item in the array. The map method can be used as an iterator, but is designed to be used for manipulation of the supplied array and returns a new array. $.merge(first, second) – Merges the second array into the first array. $.unique(array) – Removes duplicate elements (only works on arrays of DOM elements). $.extend(object) – Add functions into the jQuery namespace. $.extend(deep, target, object1, objectN) – Merge values from objects 1 to N into target object. Deep is an optional boolean that if true, tells jQuery to do a deep copy. $.grep(array, callback, invert) – Iterates through array, and returns a new array with values from the original array that satisfy the criteria specified in the callback. $.inArray(value, array) – Gets the index of the value in the array (-1 if not found). String Operations $.trim(str) – Removes whitespace from the given string. Test Operations $.isArray(obj) – Determines if the object is an array. $.isFunction(obj) – Determines if the object is a function.
  • 18. jQuery Data Can store data on one or more jQuery elements .data(name, value) value is an object Retrieves data from the first element in the jQuery object .data(name)
  • 19. Resources jQuery Main http://jquery.com http://docs.jquery.com/Downloading_jQuery jQuery API Documentation http://api.jquery.com http://docs.jquery.com jQuery UI http://jqueryui.com http://jqueryui.com/themeroller/ jQuery Blog http://blog.jquery.com/ Around The Web http://stackoverflow.com http://www.nettuts.com http://www.smashingmagazine.com Tools Visual Studio JavaScript Intellisense Support (KB958502) http://getfirebug.com/ (Firebug Firefox Plug-in) http://jsbin.com/ (JS Bin - Collaborative JavaScript Debugging) Twitter @jquery, @jqueryui, @jresig, @rem, @codylindley , @reybango, @elijahmanor, @jamespadolsey, @brandonaaron, @malsup, @pbakaus, @rworth

Editor's Notes

  1. Demo
  2. Demo
  3. Demo
  4. Demo
  5. Demo
  6. Demo
  7. Demo
  8. Demo