SlideShare a Scribd company logo
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 Lodash
Bret 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 / underscore
Nicolas 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 2
stuq
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
andyrobinson8
 
Introduction to-scala
Introduction to-scalaIntroduction to-scala
Introduction to-scala
Hamid Jafarian
 
jQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheetjQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheet
Jiby 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

Kaleehume 3222
Kaleehume 3222Kaleehume 3222
Kaleehume 3222
Ann Witherspoon
 

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

jQuery
jQueryjQuery
jQuery
Jay Poojara
 
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 Developer
Manoj Bhuva
 
JQuery New Evolution
JQuery New EvolutionJQuery New Evolution
JQuery New EvolutionAllan Huang
 
jQuery
jQueryjQuery
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
Allegient
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
azz71
 
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
James 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.pdf
RAVALCHIRAG1
 
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
James Johnson
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Nagaraju Sangam
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon 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
 
jQuery-1-Ajax
jQuery-1-AjaxjQuery-1-Ajax
jQuery-1-Ajax
 
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
 
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

20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 

Recently uploaded (20)

20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 

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