SlideShare a Scribd company logo
1 of 75
jQuery Writes less, Do More Ch. Vishwa Mohan Freelance Software Consultant & Corporate Trainer
Table of Contents jQuery Introduction jQuery Basics jQuery Core Events Animation AJAX Plugins
jQuery Introduction
Evolution
With AJAX .  .  . JavaScript has become essential to current web page development, but..  JavaScript is not a good language design. JavaScript has become bloated ,[object Object]
Browser differencesWriting JavaScript code is tedious, time-consuming and error prone.
Why you might want to use jQuery jQuery makes writing Javascript much easier.  ,[object Object]
Apply methods to sets of DOM elements.
Builder model (chain method calls)
Extensible and there are tons of libraries
Handles most of browser differences so you don’t have to Server provides data jQuery on client provides presentation.  Advantages of jQuery over JavaScript are:  ,[object Object]
Eliminates cross browser problems ,[object Object]
What is DOM ? There are four levels of standardized Document Object Model (DOM): Level 0 Level 1 Level 2 Level 3  The DOM Level 2 combines both DOM Level 1 and 2. It provides methods to access and manipulate style sheet elements, and provides further access to page elements relating to XML. This Level 2 have six different recommendations:  DOM2 Core DOM2 HTML DOM2 Style/CSS DOM2 Events DOM2 Traversal and Range DOM2 Views
What is jQuery ? jQuery is not a language, it is a well written Java Script code.  Fast and Concise.  Simplifies the interaction between HTML and Java Script.  It’s syntax is same as JavaScript Syntax.  jQuery helps,  Improve the performance of the application.  Develop most browser compatible web page.  Implement UI related critical functionality.  Fast Extensible Microsoft is shipping jQuery with Visual Studio.  jQuery supports intellisense in Visual Studio 2010 and with 2008 SP1.  You can download latest version (1.6.1) of jQuery library at			http://docs.jquery.com/Downloading_jQuery
Why jQuery ? Lightweight : 31KB in size as per v1.6.1 (Minified and Gzipped) CSS 1–3 Complaint  Cross Browser support 	(IE 6.0, Fire Fox 2, Safari 3.0+, Opera 9.0, Chrome) jQuery allows you to elegantly (and efficiently) find and manipulate the HTML elements with minimum code.  jQuery commands can be chained together.  jQuery is “DOM Scripting” Great CommunityPlugins TutorialsTestCoverage Open (free) licenseBooks
Who’s using jQuery?
jQuery Dominating  Google trends comparison of JS Framework in last 12 months.
How to Embed jQuery in your Page By assigning your jQuery script file to the “src” property of script tag.  <html>  	<head>  		<script src=“path/to/jquery-x.x.js"></script>  		<script>  			$(document).ready(function(){ 				// Start here 			});  		</script>  	</head>  	<body> … </body>  	</html>  To link jQuery remotely instead of hosting in your server: 	<script type="text/javascript“ src="http://ajax.googleapis.com/ajax/libs/   jquery/1.4.0/jquery.min.js?ver=1.4.0"></script> jQuery Code
What jQuery Provides Select DOM elements on a page.  ,[object Object],Set properties of DOM elements, in groups.  Creates, deletes, shows and hides DOM elements. Defines event behavior on a page  ,[object Object],Animations AJAX calls.
jQuery Basics
jQuery Philosophy The below is the illustration of how jQuery works: { Find Some Elements $(“div”).addClass(“xyz”); } Do something with them jQuery Object
Basic Example The following is a simple basic jQuery example how it works:  Let us assume we have the following HTML and wants to select all paragraphs: <body>  		<div> 		     <p>I m a paragraph 1</p>  		     <p>I m a paragraph 2</p>  	</div> 	      <p>I m another paragraph</p>  </body>  ,[object Object]
Add a class to all the paragraphs : $(“p”).addClass(“redStyle”);,[object Object]
The Ready Function With the help of jQuery ready() function, you can detect the state of readiness of your document to execute java script. The code included inside $(document).ready() will only run once the page is ready for JavaScript code to execute.  $(document).ready(function() { 	    		console.log('ready!'); 			}); Inside the ready function the script will be executed when DOM is ready. You can also pass named function instead of anonymous function.  5 different ways to specify the ready function jquery(document).ready(function(){…..};); jquery().ready(function(){….};) jquery(function(){ ….};) jquery(dofunc); $(dofunc);
jQuery Core
jQuery Selectors jQuery offers a set of tools for matching set of elements in a document. If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:; <=>? @[^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: . ,[object Object],Some of the selector examples:   ,[object Object]
$(“#elmtID”); 	//Selecting elements by ID. ID must be unique.
$(“div.myClass”); 	//Selecting elements by class name.
$(‘input[name=myName]’); 	//Selecting elements by attribute.
$(‘input[name$=myName]’); 	//Selecting elements it attribute ends with myName. Choosing the good selector can improve the performance of your selector.  To test whether the specified selection contain elements or not.  if ($('div.foo').length) { ... }  //If no elements it returns 0 and evaluates false.
jQuery Selectors The jQuery library allows you to select elements in your XHTML by wrapping them in $(“ ”). This $ sign in a jQuery wrapper.  You can also use single quote to wrap the element. ,[object Object]
$("#myElmtD"); // selects one HTML element with ID "myElement"
$(".myClass"); 	// selects HTML elements with class "myClass"
$("p#myElmtID"); 	// selects HTML paragraph element with ID "myElement"
$("ullia.navigation"); // selects anchors with class "navigation" that are nested in list items. jQuery also support the use of CSS selectors also. 	 ,[object Object]
$("input[type=text]"); // selects inputs that have specified type
$("a:first"); // selects the first anchor on the page
$("p:odd"); // selects all odd numbered paragraphs
$("li:first-child"); // selects each list item that's the first child in its list,[object Object]
$(":button"); 	// Selects any button elements (inputs or buttons)
$(":radio"); 	// Selects radio buttons
$(":checkbox"); 	// Selects checkboxes
$(":checked"); 	// Selects checkboxes or radio buttons that are selected
$(":header"); 	// Selects header elements (h1, h2, h3, etc.)
$(":disabled"); 	// Selects disabled form elements. (Enabled also there)
$(":img"); 		// Select inputs with type=“image”.
$(":file"); 		// Select inputs with type=“file”.
$(":password");		// Select inputs with type=“password”.,[object Object]
$(‘#id’)		id of element.
$(‘p’)		tag name.
$(‘.class’)		CSS class
$(‘p.class’)		<p> elements having the CSS class
$(‘p:first’)	$(‘p:last’)	$(‘p:odd’) $(‘p:even’)
$(‘p:eq(2)’)		gets the 2nd <p> element (1 based)
$(‘p’)[1]		gets the 2nd <p> element (0 based)
$(‘p:nth-child(3))	gets the 3rd <p> element of the parent. n=even, odd too.
$(‘p:nth-child(5n+1)’)	gets the 1st element after every 5th one
$(‘p a’)		<a> elements, descended from a <p>
$(‘p>a’)		<a> elements, direct child of a <p>
$(‘p+a’)		<a> elements, directly following a <p>
$(‘p, a’)		<p> and <a> elements
$(‘li:has(ul)’)	<li> elements that have at least one <ul> descendent
$(‘:not(p)’)		all elements but <p> elements
$(‘p:hidden’)	only <p> elements that are hidden
$(‘p:empty’)	<p> elements that have no child elements
$(‘img’[alt])	<img> elements having an alt attribute,[object Object]
$(‘a’[href$=pdf])	//Select <a> elmt with an href attribute ending with pdf
$(‘a’[href*=ntpcug])	//Select <a> elmt with an href attribute containing ‘ntpcug”. ,[object Object]
jQuery Core Methods Most of the jQuery methods are called on jQuery objects. These are said to be part of the $.fn namespace and are called as jQuery object methods.  There are several other methods that do not act on a selection, these are part of jQuery (i.e., $) namespace and are best thought of as core jQuery methods.   Methods in the $ namespace (or jQuery namespace) are called as utility methods and do not work with selections.  Some of the utility methods are: ,[object Object]
$.each()
$.proxy()	    //Returns a function that will always run in the provided scope.
$.inArray()	    //Return a value’s index in an Array.
$.extend()	     //Change the properties of the first object using properties 			     // of subsequent objects.  There are few cases the $.fn namespace and jQuery core name space methods have same name. (Eg: $.each and $.fn.each).
Traversing Elements  Once you have a jQuery selection, you can find other elements using your selection as a starting point. With the help of jQuery traversal methods you can move around DOM tree. The below are the few traversal methods defined in jQuery:  ,[object Object]
$('div:visible').parent();

More Related Content

What's hot

Java servlets
Java servletsJava servlets
Java servlets
lopjuan
 

What's hot (20)

Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Java servlets
Java servletsJava servlets
Java servlets
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
Css3
Css3Css3
Css3
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
Id and class selector
Id and class selectorId and class selector
Id and class selector
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
javascript objects
javascript objectsjavascript objects
javascript objects
 

Viewers also liked

Viewers also liked (11)

Plm Open Hours - Ersatzteilkataloge und Produktdokumentation
Plm Open Hours - Ersatzteilkataloge und ProduktdokumentationPlm Open Hours - Ersatzteilkataloge und Produktdokumentation
Plm Open Hours - Ersatzteilkataloge und Produktdokumentation
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Linq
LinqLinq
Linq
 
LINQ and LINQPad
LINQ and LINQPadLINQ and LINQPad
LINQ and LINQPad
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
Linq
LinqLinq
Linq
 
OPC Unified Architecture
OPC Unified ArchitectureOPC Unified Architecture
OPC Unified Architecture
 
Introduccion a LINQ
Introduccion a LINQIntroduccion a LINQ
Introduccion a LINQ
 
The ROI of Trust in Social Selling
The ROI of Trust in Social SellingThe ROI of Trust in Social Selling
The ROI of Trust in Social Selling
 

Similar to jQuery

J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
testingphase
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
Mark Rackley
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
Laila Buncab
 

Similar to jQuery (20)

JQuery
JQueryJQuery
JQuery
 
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
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
J query
J queryJ query
J query
 
J Query
J QueryJ Query
J Query
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks Trivia
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
 
J query training
J query trainingJ query training
J query training
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 

More from Vishwa Mohan (13)

WPF
WPFWPF
WPF
 
Wwf
WwfWwf
Wwf
 
Da package usersguide
Da package usersguideDa package usersguide
Da package usersguide
 
Dareadme
DareadmeDareadme
Dareadme
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Uml
UmlUml
Uml
 
Xml
XmlXml
Xml
 
Real Time Systems &amp; RTOS
Real Time Systems &amp; RTOSReal Time Systems &amp; RTOS
Real Time Systems &amp; RTOS
 
Embedded Linux
Embedded LinuxEmbedded Linux
Embedded Linux
 
Introduction To Embedded Systems
Introduction To Embedded SystemsIntroduction To Embedded Systems
Introduction To Embedded Systems
 
Microsoft.Net
Microsoft.NetMicrosoft.Net
Microsoft.Net
 
Zig Bee
Zig BeeZig Bee
Zig Bee
 
WCF
WCFWCF
WCF
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

jQuery