SlideShare a Scribd company logo
Presented By: Sony Jain
What  is  jQueryJavascript LibraryFast and ConciseSimplifies the interaction between HTML and JavaScript
Why  jQuery ?Cross Browser (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome)Light WeightSupports AJAXAnimationRich UI
Embed in your page<html> 	<head> 		<script src=“path/to/jquery-x.x.x.js">      </script>     <script> $(document).ready(function(){				// Start here});	   </script> 	</head> 	<body> … </body> </html>
jQuery  philosophyFind Some Elements$(“div”).addClass(“xyz”);}Do something with themjQuery Object
A Basic Example$(“p”).addClass(“red”);Selects all paragraphs. Adds a class to them.This avoids-<body> <div><p class=“red”>I m a paragraph -1</p>    	<p class=“red”>I m a paragraph -2</p>   </div><p class=“red”>I m another paragraph</p> </body>
Selector BasicsSelecting By Id$(“#header”)Selecting By Class$(“.updated”)Selecting by tag name$(“table”)Combine them$(“table.user-list”)$(“#footer ul.menuli”)
Basic Selector Example$(“ul.menuli”)<body> 	<div id=“header”> <span id=“logo”>Logo here…</span>		  <ul class=“menu”><li>user name</li>						…..			<li>logout</li>		  </ul>	</div>	……</body>
Jquery  Eventsclick(), bind(), unbind(), change(), keyup(), keydown,      …..and many moreStart when DOM is ready$(document).ready(function(){ 	   $(selector).eventName(function(){…});  });
Event Example$(document).ready(function(){ 	$(“#message”).click(function(){			$(this).hide();	})}); <span id=“message” onclick=“…”> blah blah </span>
Iterating  thro’  Elements.each()To iterate, exclusively, over a jQuery object$.each()To iterate over any collection, whether it is a map (JavaScript object) or an array.
.each()  Example<script type="text/javascript">    $(document).ready(function () {        $("span").click(function () {$("li").each(function () {                $(this).toggleClass("example");            });        });    });</script>
$.each()  Examplevararr = ["one", "two", "three", "four", "five"];varobj = { one: 1, two: 2, three: 3, four: 4, five: 5 };    $(document).ready(function () {jQuery.each(arr, function () {            $("#" + this).text("Mine is " + this + ".");            return (this != "three"); // will stop running after "three"        });jQuery.each(obj, function (i, val) {            $("#" + i).append(document.createTextNode(" - " + val));        });    });
$.extend()Merge the contents of two or more objects together into the first object.Syntax$.extend( [ deep ], target, object1, [ objectN ] )deep      -  If true, the merge becomes recursive.target    -  The object to extend. It will receive the new properties.object1  -  An object containing additional properties to                      merge in.objectN  -  Additional objects containing properties to                       merge in.
$.extend() - ExampleMerge two objects, modifying the firstvar settings = { validate: false, limit: 5, name: "foo" };var options = { validate: true, name: "bar" };jQuery.extend(settings, options);Result:settings == { validate: true, limit: 5, name: "bar" }
$.extend() - ExampleMerge two objects recursively, modifying the first. var settings = { validate: false,                         font: {family: Arial, size: 12px},                        name: “abc" };var options = { validate: true,                         font: {family: Verdana},                        name: “xyz" };jQuery.extend( true, settings, options);Result:settings == { validate: true,                      font: {family: Verdana, size: 12px},                      name: “xyz" }
$.extend() - ExampleMerge defaults and options, without modifying the defaults. This is       a common plugin development pattern.var empty = {}var defaults = { validate: false, limit: 5, name: "foo" };var options = { validate: true, name: "bar" };var settings = $.extend(empty, defaults, options);Result:settings == { validate: true, limit: 5, name: "bar" }empty == { validate: true, limit: 5, name: "bar" }
$.fn.extend()Extends the jQuery element set to provide new methods      (used to make a typical jQuery plugin).Syntax//You need an anonymous function to wrap around your function to avoid conflict(function($){     //Attach this new method to jQuery    $.fn.extend({                  //This is where you write your plugin's name        pluginname: function() {             //Iterate over the current set of matched elements            return this.each(function() {                             //code to be inserted here                         });        }    });
$.fn.extend() - ExampleReverse  Text  of  Odd  rows<script type="text/javascript">$(document).ready(function () {           $('ulli:odd').reverseText({ minlength: 6, maxlength: 10 });    });</script><body>    <form id="form1" runat="server">    <div>        <ul id="menu">        <li>Home</li>        <li>Posts</li>        <li>About</li>        <li>Contact Us</li></ul>    </div>    </form></body>Desired Result
$.fn.extend() - Example(function($) {  // jQuery plugin definition  $.fn.reverseText = function(params) {              //$.fn.extend({ reverseText: function(params) {…// merge default and user parameters  params = $.extend( {minlength: 0, maxlength: 99999}, params);  // traverse all nodes  this.each(function() {  // express a single node as a jQuery object  var $t = $(this);               // find text  varorigText = $t.text(), newText = '';  // text length within defined limits?  if (origText.length >= params.minlength &&  origText.length <= params.maxlength) {  // reverse text  for (vari = origText.length-1; i >= 0; i--) newText += origText.substr(i, 1);                   $t.text(newText);               }           });           // allow jQuery chaining  return this;       }; });
Jquery  and  AJAXjQuery.ajax() or $.ajax() Performs an asynchronous HTTP (Ajax)    request.
jQuery.ajax()The $.ajax() function underlies all Ajax requests    sent by jQueryAt its simplest, the $.ajax() function can be called    with no arguments:    Note: Default settings can be set globally by using the$.ajaxSetup() functionSeveral higher-level alternatives like $.get() and .load()     are available and are easier to use. If less common     options are required, though, $.ajax() can be used more     flexibly.$.ajax();
jQuery.ajax()Syntax       $.ajax({               type: type,              url: url,               data: data,               success: success,dataType: dataType     });Type that describes whether the request if GET or POST URL of the HTTPHandlerData specifying the querystringSuccess defining a function which manipulates the response from the handler DataTypeDifferent data handling can be achieved by using the dataType      option. The dataType can be plain xml, html, json, jsonp, script, or      text.
jQuery.ajax() : ExampleSave some data to the server and notify the user once it's complete.     $.ajax({   type: "POST",   url: "some.aspx",   data: "name=John&location=Boston",   success: function(msg){     alert( "Data Saved: " + msg );    }});
Thank You

More Related Content

What's hot (19)

PDF
Doctrine 2
zfconfua
 
KEY
Php 101: PDO
Jeremy Kendall
 
PDF
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
KEY
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
PDF
Your code sucks, let's fix it
Rafael Dohms
 
PDF
Future of HTTP in CakePHP
markstory
 
PDF
Chapter 8- Advanced Views and URLconfs
Vincent Chien
 
PDF
PHP Language Trivia
Nikita Popov
 
PDF
You code sucks, let's fix it
Rafael Dohms
 
PDF
New in cakephp3
markstory
 
PPTX
jQuery from the very beginning
Anis Ahmad
 
PDF
WordPress London 16 May 2012 - You don’t know query
l3rady
 
PDF
PHP 5.3 and Lithium: the most rad php framework
G Woo
 
PDF
DBIx::Class introduction - 2010
leo lapworth
 
PPTX
Topological indices (t is) of the graphs to seek qsar models of proteins com...
Jitendra Kumar Gupta
 
PDF
DBIx::Class beginners
leo lapworth
 
PDF
Dependency Injection IPC 201
Fabien Potencier
 
PPTX
jQuery PPT
Dominic Arrojado
 
PDF
The Zen of Lithium
Nate Abele
 
Doctrine 2
zfconfua
 
Php 101: PDO
Jeremy Kendall
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
Your code sucks, let's fix it
Rafael Dohms
 
Future of HTTP in CakePHP
markstory
 
Chapter 8- Advanced Views and URLconfs
Vincent Chien
 
PHP Language Trivia
Nikita Popov
 
You code sucks, let's fix it
Rafael Dohms
 
New in cakephp3
markstory
 
jQuery from the very beginning
Anis Ahmad
 
WordPress London 16 May 2012 - You don’t know query
l3rady
 
PHP 5.3 and Lithium: the most rad php framework
G Woo
 
DBIx::Class introduction - 2010
leo lapworth
 
Topological indices (t is) of the graphs to seek qsar models of proteins com...
Jitendra Kumar Gupta
 
DBIx::Class beginners
leo lapworth
 
Dependency Injection IPC 201
Fabien Potencier
 
jQuery PPT
Dominic Arrojado
 
The Zen of Lithium
Nate Abele
 

Viewers also liked (8)

PDF
jQuery Effects
Adelon Zeta
 
PPT
Introduction to j query
thewarlog
 
PPTX
JQuery
Rahul Jain
 
PDF
Introducing jQuery
Wildan Maulana
 
PPT
Jquery presentation
Narendra Dabhi
 
PPT
jQuery Beginner
kumar gaurav
 
PPTX
jQuery presentation
Mahesh Reddy
 
PPTX
jQuery Best Practice
chandrashekher786
 
jQuery Effects
Adelon Zeta
 
Introduction to j query
thewarlog
 
JQuery
Rahul Jain
 
Introducing jQuery
Wildan Maulana
 
Jquery presentation
Narendra Dabhi
 
jQuery Beginner
kumar gaurav
 
jQuery presentation
Mahesh Reddy
 
jQuery Best Practice
chandrashekher786
 
Ad

Similar to JQuery Presentation (20)

PPT
PHP
webhostingguy
 
PPT
Jquery Best Practices
brinsknaps
 
PPTX
JavaScript Literacy
David Jacobs
 
PDF
jQuery secrets
Bastian Feder
 
PDF
What's new in jQuery 1.5
Martin Kleppe
 
PPT
Framework
Nguyen Linh
 
PPTX
Ajax for dummies, and not only.
Nerd Tzanetopoulos
 
ODP
JQuery introduction
Pradeep Saraswathi
 
PDF
Unit testing with zend framework tek11
Michelangelo van Dam
 
ODP
vfsStream - effective filesystem mocking
Sebastian Marek
 
KEY
Unit testing zend framework apps
Michelangelo van Dam
 
KEY
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
KEY
Unit testing with zend framework PHPBenelux
Michelangelo van Dam
 
PPT
vfsStream - a better approach for file system dependent tests
Frank Kleine
 
PPT
PHP Unit Testing
Tagged Social
 
PPT
Php Reusing Code And Writing Functions
mussawir20
 
PDF
The Beauty Of Java Script V5a
rajivmordani
 
PDF
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
PPT
Introduction to JQuery
MobME Technical
 
Jquery Best Practices
brinsknaps
 
JavaScript Literacy
David Jacobs
 
jQuery secrets
Bastian Feder
 
What's new in jQuery 1.5
Martin Kleppe
 
Framework
Nguyen Linh
 
Ajax for dummies, and not only.
Nerd Tzanetopoulos
 
JQuery introduction
Pradeep Saraswathi
 
Unit testing with zend framework tek11
Michelangelo van Dam
 
vfsStream - effective filesystem mocking
Sebastian Marek
 
Unit testing zend framework apps
Michelangelo van Dam
 
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
Unit testing with zend framework PHPBenelux
Michelangelo van Dam
 
vfsStream - a better approach for file system dependent tests
Frank Kleine
 
PHP Unit Testing
Tagged Social
 
Php Reusing Code And Writing Functions
mussawir20
 
The Beauty Of Java Script V5a
rajivmordani
 
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Introduction to JQuery
MobME Technical
 
Ad

JQuery Presentation

  • 2. What is jQueryJavascript LibraryFast and ConciseSimplifies the interaction between HTML and JavaScript
  • 3. Why jQuery ?Cross Browser (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome)Light WeightSupports AJAXAnimationRich UI
  • 4. Embed in your page<html> <head> <script src=“path/to/jquery-x.x.x.js"> </script> <script> $(document).ready(function(){ // Start here}); </script> </head> <body> … </body> </html>
  • 5. jQuery philosophyFind Some Elements$(“div”).addClass(“xyz”);}Do something with themjQuery Object
  • 6. A Basic Example$(“p”).addClass(“red”);Selects all paragraphs. Adds a class to them.This avoids-<body> <div><p class=“red”>I m a paragraph -1</p> <p class=“red”>I m a paragraph -2</p> </div><p class=“red”>I m another paragraph</p> </body>
  • 7. Selector BasicsSelecting By Id$(“#header”)Selecting By Class$(“.updated”)Selecting by tag name$(“table”)Combine them$(“table.user-list”)$(“#footer ul.menuli”)
  • 8. Basic Selector Example$(“ul.menuli”)<body> <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”><li>user name</li> ….. <li>logout</li> </ul> </div> ……</body>
  • 9. Jquery Eventsclick(), bind(), unbind(), change(), keyup(), keydown, …..and many moreStart when DOM is ready$(document).ready(function(){ $(selector).eventName(function(){…}); });
  • 11. Iterating thro’ Elements.each()To iterate, exclusively, over a jQuery object$.each()To iterate over any collection, whether it is a map (JavaScript object) or an array.
  • 12. .each() Example<script type="text/javascript"> $(document).ready(function () { $("span").click(function () {$("li").each(function () { $(this).toggleClass("example"); }); }); });</script>
  • 13. $.each() Examplevararr = ["one", "two", "three", "four", "five"];varobj = { one: 1, two: 2, three: 3, four: 4, five: 5 }; $(document).ready(function () {jQuery.each(arr, function () { $("#" + this).text("Mine is " + this + "."); return (this != "three"); // will stop running after "three" });jQuery.each(obj, function (i, val) { $("#" + i).append(document.createTextNode(" - " + val)); }); });
  • 14. $.extend()Merge the contents of two or more objects together into the first object.Syntax$.extend( [ deep ], target, object1, [ objectN ] )deep - If true, the merge becomes recursive.target - The object to extend. It will receive the new properties.object1 - An object containing additional properties to merge in.objectN - Additional objects containing properties to merge in.
  • 15. $.extend() - ExampleMerge two objects, modifying the firstvar settings = { validate: false, limit: 5, name: "foo" };var options = { validate: true, name: "bar" };jQuery.extend(settings, options);Result:settings == { validate: true, limit: 5, name: "bar" }
  • 16. $.extend() - ExampleMerge two objects recursively, modifying the first. var settings = { validate: false, font: {family: Arial, size: 12px}, name: “abc" };var options = { validate: true, font: {family: Verdana}, name: “xyz" };jQuery.extend( true, settings, options);Result:settings == { validate: true, font: {family: Verdana, size: 12px}, name: “xyz" }
  • 17. $.extend() - ExampleMerge defaults and options, without modifying the defaults. This is a common plugin development pattern.var empty = {}var defaults = { validate: false, limit: 5, name: "foo" };var options = { validate: true, name: "bar" };var settings = $.extend(empty, defaults, options);Result:settings == { validate: true, limit: 5, name: "bar" }empty == { validate: true, limit: 5, name: "bar" }
  • 18. $.fn.extend()Extends the jQuery element set to provide new methods (used to make a typical jQuery plugin).Syntax//You need an anonymous function to wrap around your function to avoid conflict(function($){     //Attach this new method to jQuery    $.fn.extend({                  //This is where you write your plugin's name        pluginname: function() {             //Iterate over the current set of matched elements            return this.each(function() {                             //code to be inserted here                         });        }    });
  • 19. $.fn.extend() - ExampleReverse Text of Odd rows<script type="text/javascript">$(document).ready(function () { $('ulli:odd').reverseText({ minlength: 6, maxlength: 10 }); });</script><body> <form id="form1" runat="server"> <div> <ul id="menu"> <li>Home</li> <li>Posts</li> <li>About</li> <li>Contact Us</li></ul> </div> </form></body>Desired Result
  • 20. $.fn.extend() - Example(function($) { // jQuery plugin definition $.fn.reverseText = function(params) { //$.fn.extend({ reverseText: function(params) {…// merge default and user parameters params = $.extend( {minlength: 0, maxlength: 99999}, params); // traverse all nodes this.each(function() { // express a single node as a jQuery object var $t = $(this); // find text varorigText = $t.text(), newText = ''; // text length within defined limits? if (origText.length >= params.minlength && origText.length <= params.maxlength) { // reverse text for (vari = origText.length-1; i >= 0; i--) newText += origText.substr(i, 1); $t.text(newText); } }); // allow jQuery chaining return this; }; });
  • 21. Jquery and AJAXjQuery.ajax() or $.ajax() Performs an asynchronous HTTP (Ajax) request.
  • 22. jQuery.ajax()The $.ajax() function underlies all Ajax requests sent by jQueryAt its simplest, the $.ajax() function can be called with no arguments: Note: Default settings can be set globally by using the$.ajaxSetup() functionSeveral higher-level alternatives like $.get() and .load() are available and are easier to use. If less common options are required, though, $.ajax() can be used more flexibly.$.ajax();
  • 23. jQuery.ajax()Syntax $.ajax({ type: type, url: url, data: data, success: success,dataType: dataType });Type that describes whether the request if GET or POST URL of the HTTPHandlerData specifying the querystringSuccess defining a function which manipulates the response from the handler DataTypeDifferent data handling can be achieved by using the dataType option. The dataType can be plain xml, html, json, jsonp, script, or text.
  • 24. jQuery.ajax() : ExampleSave some data to the server and notify the user once it's complete. $.ajax({   type: "POST",   url: "some.aspx",   data: "name=John&location=Boston",   success: function(msg){     alert( "Data Saved: " + msg );    }});