SlideShare a Scribd company logo
jQuery Javascript that doesn't suck! Presented By Mir Nazim www.mirnazim.com [email_address]
WHAT and WHEN John Resig -  www.ejohn.org Released at BarCamp NYC on Jan 2006 jQuery 1.0 out on Aug 2006 version 1.1.3 latest ~ 800% faster for DOM processing numerous other improvements
WHY Doesn’t mess with the language (Prototype) Doesn’t try to be Python  (Mochikit) Only essentials: > 20 KB  (Scriptaculous, Dojo) More than cosmetic effects  (Moo.fx) Makes common tasks a breeze
OTHER REASONS Great Documentaions Great community Tons of plugins Works everywhere RELIABLY IE 6+, Firefox, Safari 2+, and Opera 9+
What jQuery Deos GENRAL PURPOSE ABSTRACTION LAYER FOR COMMON WEB SCRIPTING  TASKS
What's Good in it Access parts of a page Modify the appearance of a page Alter the content of a page Respond to a user's interaction Add animation to a page Retrieve information (Ajax) Simplify common tasks
How jQuery does it Leverage knowledge of CSS Abstract away browser quirks Always work with sets Allow multiple actions in one line Support extensions
Getting Started <head> <script src=&quot;jquery.js&quot; type=&quot;text/javascript&quot;> </script> <script type=&quot;text/javascript&quot;> $(document).ready(function(){ // your stuff goes here }); </script> </head>
The  $()  function A factory for jQuery object Provides a jQuery instance All operations are done using $()
Element Selection - CSS $(document).ready(function(){ //select all ”p” elements $(”p”); //select an element with id=”soem-id” $(”#some-id”); //select all elements with class=”soem-class” $(”.some-class”); });
More Element Selection /* select 'li' elements that are children of 'ul' with id=”some-ul” */ $('ul#some-ul > li')
Element Selection - XPath //all links with a title attributes $('a[@title]') //all ”divs” containing on ”ol” element $('div[ol]')
Xpath + RegEx //all links with ”href” starting with ”mailto:” $('a[@href^=&quot;mailto:&quot;]') //all links with ”href” ending with ”.pdf” $('a[@href$=&quot;.pdf&quot;]') //all links that contain ”mysite.com” anywhere in ”href” $('a[@href*=&quot;mysite.com&quot;]')
Custom Selectors //selects 2 nd  div from the set $('div.someclass:eq(0)') // same as above but CSS based $('div.someclass:nth-child(1)')
Select Even/Odd Rows of table $('tr:odd')  //all odd rows $('tr:even')  //all even rows
DOM Traversal Same Effect, Different way $('tr').filter(':odd')  //all odd rows $('tr').filter(':even') //all even rows
DOM Traversal //select the parent element of ”th” $('th').parent() //select all even ”tr” but not that contain a ”th” $('tr:not([th]):even') //select all odd ”tr” but not that contain a ”th” $('tr:not([th]):odd')
More DOM $('td:contains(&quot;Henry&quot;)').siblings() $('td:contains(&quot;Henry&quot;)').parent().find('td:gt(0)') $('td:contains(&quot;Henry&quot;)').parent().find('td') .not(':contains(&quot;Henry&quot;)') ) $('td:contains(&quot;Henry&quot;)').parent().find('td:eq(1)')
Method Chaining //get every cell containing &quot;Henry&quot; $('td:contains(&quot;Henry&quot;)') //get its parent .parent() //find inside the parent the 2nd cell .find('td:eq(1)') //add the &quot;highlight&quot; class to that cell .addClass(highlight') //revert back to the parent of the cell containing &quot;Henry&quot; .end() //find inside the parent the 3rd cell .find('td:eq(2)') //add the &quot;highlight&quot; class to that cell .addClass('highlight');
Events $('#some-element').bind('click',function() { $('body').addClass('large'); //some more stuff //even some more stuff }); use event names without on part. E.G onClick => click onKeyPress => keypress
Compound Events // add and remove class on alternate clicks $('#some-element'). toggle (function() { $('#switcher.button').addClass('hidden'); }, function() { $('#switcher.button').removeClass('hidden'); });
One compound event //works like ”:hover” pseudo class $('#some-element').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
Manipulating Attributes //change the ”title” attribute of ”a” element where id=”some-id” $('a#some-id').attr({'title': 'Some Text here'}); //more than one at a time $('a#some-id').attr({ 'title':'Some Text here', 'href':'www.example.com', 'id':'some-other-id', });
Changing the tag content //eq of element.innerHTML() $('#some-div').html() //eq of element.innerHTML = some-var $('#some-div').html(some-var) //eq of some-input.value $('input').val() //eq of some-input.value = some-var $('input').val(some-var)
AJAX /* when a buttong with id=”some-button” is clicked load ”a.html” in div with id=”some-div” */ $('#some-button').click(function() { $('#some-div').load('a.html'); });
AJAX + JSON $('#some-button').click(function() { $.getJSON('b.json'); });
Take action on data $('#some-button').click(function() { $.getJSON('b.json', function(data) { // do some stuff with data you just go });
Execute a script $('#some-button').click(function() { $.getScript('c.js'); });
Load other data formats $('#some-button').click(function() { $.get('my-format.data', function(data) { //handle your data way you want }); });
A GET request $.get('e.php',  {'term': $(this).text()}, function(data) { $('#some-div').html(data); } );
POST request $.post('e.php',  {'term': $(this).text()},  function(data) { $('#some-div').html(data); } );
AJAX observers $('#loading'). ajaxStart (function() { $(this).show(); }). ajaxStop (function() { $(this).hide(); });
There is more Loads of good quality plugins for Extended AJAX functionality Cool Effects Extensions to core jQuery much more http://jquery.com/plugins http://doc.jquery.com/Plugins
Resources http://doc.jquery.com www.visualjquery.com www.Google.com 15 days of jQuery (blog) Learning jQuery (blog)
 
Thanks A Millions ? QEUSTIONS

More Related Content

What's hot (20)

PDF
Javascript and DOM
Brian Moschel
 
PDF
Flexbox and Grid Layout
Rachel Andrew
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PPTX
jQuery
Jay Poojara
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPTX
Flexbox
Netcetera
 
PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PPTX
JavaScript Promises
L&T Technology Services Limited
 
PPTX
JavaScript Basic
Finsa Nurpandi
 
PPTX
Javascript 101
Shlomi Komemi
 
PDF
HTML and CSS crash course!
Ana Cidre
 
PPTX
Basic HTML
Sayan De
 
PPT
Introduction to jQuery
Andres Baravalle
 
PPTX
Css selectors
Dinesh Kumar
 
KEY
HTML presentation for beginners
jeroenvdmeer
 
PPTX
jQuery from the very beginning
Anis Ahmad
 
PPT
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
PPT
Cookies and sessions
Lena Petsenchuk
 
ODP
HTML5
Hatem Mahmoud
 
PPTX
Flex box
Harish Karthick
 
Javascript and DOM
Brian Moschel
 
Flexbox and Grid Layout
Rachel Andrew
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
jQuery
Jay Poojara
 
jQuery for beginners
Arulmurugan Rajaraman
 
Flexbox
Netcetera
 
JavaScript & Dom Manipulation
Mohammed Arif
 
JavaScript Promises
L&T Technology Services Limited
 
JavaScript Basic
Finsa Nurpandi
 
Javascript 101
Shlomi Komemi
 
HTML and CSS crash course!
Ana Cidre
 
Basic HTML
Sayan De
 
Introduction to jQuery
Andres Baravalle
 
Css selectors
Dinesh Kumar
 
HTML presentation for beginners
jeroenvdmeer
 
jQuery from the very beginning
Anis Ahmad
 
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Cookies and sessions
Lena Petsenchuk
 
Flex box
Harish Karthick
 

Similar to Introduction to jQuery (20)

PPT
JQuery Basics
Alin Taranu
 
PPT
Introduction to JQuery
MobME Technical
 
KEY
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
PPT
jQuery Performance Rules
nagarajhubli
 
PPT
jQuery Fundamentals
Doncho Minkov
 
PPT
jQuery Intro
Jason Noble
 
PPT
Jquery Best Practices
brinsknaps
 
PPT
Getting Started with jQuery
Shea Frederick
 
PPT
Designers Guide To jQuery
Steve Krueger
 
PPT
Introduction to Prototype JS Framework
Mohd Imran
 
PDF
Cheap frontend tricks
ambiescent
 
PPTX
JQuery Presentation
Sony Jain
 
PPTX
Introduction to jQuery
Gunjan Kumar
 
PPT
Jquery presentation
guest5d87aa6
 
ODP
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
PDF
jQuery - 10 Time-Savers You (Maybe) Don't Know
girish82
 
PPT
J Query Public
pradeepsilamkoti
 
PPT
Jquery
guest1f6f380f
 
PDF
Intro to jquery
Dan Pickett
 
JQuery Basics
Alin Taranu
 
Introduction to JQuery
MobME Technical
 
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
jQuery Performance Rules
nagarajhubli
 
jQuery Fundamentals
Doncho Minkov
 
jQuery Intro
Jason Noble
 
Jquery Best Practices
brinsknaps
 
Getting Started with jQuery
Shea Frederick
 
Designers Guide To jQuery
Steve Krueger
 
Introduction to Prototype JS Framework
Mohd Imran
 
Cheap frontend tricks
ambiescent
 
JQuery Presentation
Sony Jain
 
Introduction to jQuery
Gunjan Kumar
 
Jquery presentation
guest5d87aa6
 
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
girish82
 
J Query Public
pradeepsilamkoti
 
Intro to jquery
Dan Pickett
 
Ad

More from manugoel2003 (10)

PPT
Css Specificity
manugoel2003
 
PPT
Subversion (SVN)
manugoel2003
 
PPT
Zend Framework
manugoel2003
 
PPT
Drupal CMS
manugoel2003
 
PPT
Securing Your Web Server
manugoel2003
 
PPS
PHP Security
manugoel2003
 
ODP
Drupal Best Practices
manugoel2003
 
PPT
OOP in JavaScript
manugoel2003
 
PPT
CiviCRM
manugoel2003
 
PPT
PHP Documentor
manugoel2003
 
Css Specificity
manugoel2003
 
Subversion (SVN)
manugoel2003
 
Zend Framework
manugoel2003
 
Drupal CMS
manugoel2003
 
Securing Your Web Server
manugoel2003
 
PHP Security
manugoel2003
 
Drupal Best Practices
manugoel2003
 
OOP in JavaScript
manugoel2003
 
CiviCRM
manugoel2003
 
PHP Documentor
manugoel2003
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 

Introduction to jQuery

  • 1. jQuery Javascript that doesn't suck! Presented By Mir Nazim www.mirnazim.com [email_address]
  • 2. WHAT and WHEN John Resig - www.ejohn.org Released at BarCamp NYC on Jan 2006 jQuery 1.0 out on Aug 2006 version 1.1.3 latest ~ 800% faster for DOM processing numerous other improvements
  • 3. WHY Doesn’t mess with the language (Prototype) Doesn’t try to be Python (Mochikit) Only essentials: > 20 KB (Scriptaculous, Dojo) More than cosmetic effects (Moo.fx) Makes common tasks a breeze
  • 4. OTHER REASONS Great Documentaions Great community Tons of plugins Works everywhere RELIABLY IE 6+, Firefox, Safari 2+, and Opera 9+
  • 5. What jQuery Deos GENRAL PURPOSE ABSTRACTION LAYER FOR COMMON WEB SCRIPTING TASKS
  • 6. What's Good in it Access parts of a page Modify the appearance of a page Alter the content of a page Respond to a user's interaction Add animation to a page Retrieve information (Ajax) Simplify common tasks
  • 7. How jQuery does it Leverage knowledge of CSS Abstract away browser quirks Always work with sets Allow multiple actions in one line Support extensions
  • 8. Getting Started <head> <script src=&quot;jquery.js&quot; type=&quot;text/javascript&quot;> </script> <script type=&quot;text/javascript&quot;> $(document).ready(function(){ // your stuff goes here }); </script> </head>
  • 9. The $() function A factory for jQuery object Provides a jQuery instance All operations are done using $()
  • 10. Element Selection - CSS $(document).ready(function(){ //select all ”p” elements $(”p”); //select an element with id=”soem-id” $(”#some-id”); //select all elements with class=”soem-class” $(”.some-class”); });
  • 11. More Element Selection /* select 'li' elements that are children of 'ul' with id=”some-ul” */ $('ul#some-ul > li')
  • 12. Element Selection - XPath //all links with a title attributes $('a[@title]') //all ”divs” containing on ”ol” element $('div[ol]')
  • 13. Xpath + RegEx //all links with ”href” starting with ”mailto:” $('a[@href^=&quot;mailto:&quot;]') //all links with ”href” ending with ”.pdf” $('a[@href$=&quot;.pdf&quot;]') //all links that contain ”mysite.com” anywhere in ”href” $('a[@href*=&quot;mysite.com&quot;]')
  • 14. Custom Selectors //selects 2 nd div from the set $('div.someclass:eq(0)') // same as above but CSS based $('div.someclass:nth-child(1)')
  • 15. Select Even/Odd Rows of table $('tr:odd') //all odd rows $('tr:even') //all even rows
  • 16. DOM Traversal Same Effect, Different way $('tr').filter(':odd') //all odd rows $('tr').filter(':even') //all even rows
  • 17. DOM Traversal //select the parent element of ”th” $('th').parent() //select all even ”tr” but not that contain a ”th” $('tr:not([th]):even') //select all odd ”tr” but not that contain a ”th” $('tr:not([th]):odd')
  • 18. More DOM $('td:contains(&quot;Henry&quot;)').siblings() $('td:contains(&quot;Henry&quot;)').parent().find('td:gt(0)') $('td:contains(&quot;Henry&quot;)').parent().find('td') .not(':contains(&quot;Henry&quot;)') ) $('td:contains(&quot;Henry&quot;)').parent().find('td:eq(1)')
  • 19. Method Chaining //get every cell containing &quot;Henry&quot; $('td:contains(&quot;Henry&quot;)') //get its parent .parent() //find inside the parent the 2nd cell .find('td:eq(1)') //add the &quot;highlight&quot; class to that cell .addClass(highlight') //revert back to the parent of the cell containing &quot;Henry&quot; .end() //find inside the parent the 3rd cell .find('td:eq(2)') //add the &quot;highlight&quot; class to that cell .addClass('highlight');
  • 20. Events $('#some-element').bind('click',function() { $('body').addClass('large'); //some more stuff //even some more stuff }); use event names without on part. E.G onClick => click onKeyPress => keypress
  • 21. Compound Events // add and remove class on alternate clicks $('#some-element'). toggle (function() { $('#switcher.button').addClass('hidden'); }, function() { $('#switcher.button').removeClass('hidden'); });
  • 22. One compound event //works like ”:hover” pseudo class $('#some-element').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
  • 23. Manipulating Attributes //change the ”title” attribute of ”a” element where id=”some-id” $('a#some-id').attr({'title': 'Some Text here'}); //more than one at a time $('a#some-id').attr({ 'title':'Some Text here', 'href':'www.example.com', 'id':'some-other-id', });
  • 24. Changing the tag content //eq of element.innerHTML() $('#some-div').html() //eq of element.innerHTML = some-var $('#some-div').html(some-var) //eq of some-input.value $('input').val() //eq of some-input.value = some-var $('input').val(some-var)
  • 25. AJAX /* when a buttong with id=”some-button” is clicked load ”a.html” in div with id=”some-div” */ $('#some-button').click(function() { $('#some-div').load('a.html'); });
  • 26. AJAX + JSON $('#some-button').click(function() { $.getJSON('b.json'); });
  • 27. Take action on data $('#some-button').click(function() { $.getJSON('b.json', function(data) { // do some stuff with data you just go });
  • 28. Execute a script $('#some-button').click(function() { $.getScript('c.js'); });
  • 29. Load other data formats $('#some-button').click(function() { $.get('my-format.data', function(data) { //handle your data way you want }); });
  • 30. A GET request $.get('e.php', {'term': $(this).text()}, function(data) { $('#some-div').html(data); } );
  • 31. POST request $.post('e.php', {'term': $(this).text()}, function(data) { $('#some-div').html(data); } );
  • 32. AJAX observers $('#loading'). ajaxStart (function() { $(this).show(); }). ajaxStop (function() { $(this).hide(); });
  • 33. There is more Loads of good quality plugins for Extended AJAX functionality Cool Effects Extensions to core jQuery much more http://jquery.com/plugins http://doc.jquery.com/Plugins
  • 35.  
  • 36. Thanks A Millions ? QEUSTIONS