SlideShare a Scribd company logo
 
What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript
Why jQuery? Lightweight : 19KB in size  (Minified and Gzipped) CSS1 - 3 Complaint  Cross Browser  (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome)
Why jQuery? Lightweight : 19KB in size  (Minified and Gzipped) CSS1 - 3 Complaint  Cross Browser  (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome) Great Community   Plugins Tutorials   TestCoverage Open (free) license   Books
A ajax and DOM manipulation example if (!document.ELEMENT_NODE) { document.ELEMENT_NODE = 1; document.ATTRIBUTE_NODE = 2; document.TEXT_NODE = 3; document.CDATA_SECTION_NODE = 4; document.ENTITY_REFERENCE_NODE = 5; document.ENTITY_NODE = 6; document.PROCESSING_INSTRUCTION_NODE = 7; document.COMMENT_NODE = 8; document.DOCUMENT_NODE = 9; document.DOCUMENT_TYPE_NODE = 10; document.DOCUMENT_FRAGMENT_NODE = 11; document.NOTATION_NODE = 12; } document._importNode = function(node, allChildren) { switch (node.nodeType) { case document.ELEMENT_NODE: var newNode = document.createElement(node » .nodeName); /* does the node have any attributes to add? */ if (node.attributes && node.attributes » .length > 0) for (var i = 0; il = node.attributes.length; » i < il) newNode.setAttribute(node.attributes » .nodeName, node.getAttribute(node.attributes[i++] » .nodeName)); /* are we going after children too, and does » the node have any? */ if (allChildren && node.childNodes && » node.childNodes.length > 0) for (var i = 0; il = node.childNodes.length; » i < il) newNode.appendChild(document._importNode » (node.childNodes[i++], allChildren)); return newNode; break; case document.TEXT_NODE: case document.CDATA_SECTION_NODE: case document.COMMENT_NODE: return document.createTextNode(node.nodeValue); break; } };  http:// www.alistapart.com/articles/crossbrowserscripting
It’s just a single line in jQuery $(“#content”).load(“page.html #content”);
Who’s using jQuery? http:// docs.jquery.com/Sites_Using_jQuery
Dominating the world Google trends comparison of last JS framework 12 months http:// www.google.com/trends?q =jQuery%2C+prototype%2C+yui%2C+dojo%2C+mootools&ctab=0&geo= all&date = ytd&sort =0
Let’s Start Download jQuery http:// docs.jquery.com/Downloading_jQuery
Embed in you page <html>  <head>  <script src=“ path/to/jquery-x.x.js &quot;></script>  </head>  <body> … </body>  </html>
Embed in you page <html>  <head>  <script src=&quot; path/to/jquery-x.x.js &quot;></script>  <script>  $(document).ready(function(){ // Start here });  </script>  </head>  <body> … </body>  </html>
$(“div”). addClass(“xyz”); Find Some Elements Do something with them { } jQuery Object jQuery philosophy
A Basic Example <body>  <div> <p>I m a paragraph 1</p>  <p>I m a paragraph 2</p>  </div> <p>I m another paragraph</p>  </body>
A Basic Example <body>  <div> <p>I m a paragraph 1</p>  <p>I m a paragraph 2</p>  </div> <p>I m another paragraph</p>  </body>  Select all paragraphs.  $(“p”)
A Basic Example <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>  Select all paragraphs. Add a class to them. $(“p”).addClass(“red”);
Selector Basics Just pass a  selector  to  $() What is  selector? Use any CSS selector
Selector Basics Think about your simplest css file. #header{ margin : 0 auto; } div{ margin : 0px; padding : 0px } ul.menu li{ … .. }
Selector Basics The  red  colored items are  selectors #header { margin : 0 auto; } div { margin : 0px; padding : 0px } ul.menu li { … .. }
Selector Basics Selecting By Id $(“#header”) Selecting using selectors
Selector Basics Selecting By Id $(“#header”) Selecting By Class $(“.updated”) Selecting using selectors
Selector Basics Selecting By Id $(“#header”) Selecting By Class $(“.updated”) Selecting by tag name $(“table”)  Selecting using selectors
Selector Basics Selecting By Id $(“#header”) Selecting By Class $(“.updated”) Selecting by tag name $(“table”) Combine them $(“table.user-list”) $(“#footer ul.menu li”) Selecting using selectors
Basic Selector Example This is my page <body>  <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
Basic Selector Example $(“#header”) <body>  <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
Basic Selector Example $(“ul.menu”) <body>  <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
Basic Selector Example $(“ul.menu li”) <body>  <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
Using filters for selecting Basic Filters :first, :last, :even, :odd, …...
Basic Filters Example Student list table. Lets make it zebra. Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 Mizan XII 5 Karim VI 2 Satisfactory
Basic Filters Example $(“#students tr:even”).css(“background-color”, “#dde”) Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 Mizan XII 5 Karim VI 2 Satisfactory
Using filters for selecting Basic Filters :first, :last, :even, :odd, …... Content Filters: :empty , :contains(text), :has(selector), …..
Content Filters Example $(“#students tr:even”).css(“background-color”, “#dde”); $(“#students td.comment:empty”).text(“No Comment”); Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 No Comment Mizan XII 5 No Comment Karim VI 2 Satisfactory
Using filters for selecting Basic Filters :first, :last, :even, :odd, …... Content Filters: :empty , :contains(text), :has(selector), ….. Attribute Filters:  [attribute], [attribute=value], [attribute!=value], …..
Attribute Filters Example $(“#students tr:even”).css(“background-color”, “#dde”); $(“#students td.comment:empty”).text(“No Comment”); $(“#students td[align=‘center']&quot;).addClass(“ocean”); Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 No Comment Mizan XII 5 No Comment Karim VI 2 Satisfactory
Using filters for selecting Basic Filters :first, :last, :even, :odd, …... Content Filters: :empty , :contains(text), :has(selector), ….. Attribute Filters:  [attribute], [attribute=value], [attribute!=value], ….. Forms :input, :text, :submit, :password, ….. :enabled, :disabled, :checked, …..
Forms Selector Example $(&quot;:submit&quot;) .click(function(e){ … }); $(&quot;input:disabled&quot;) .val(“You cannot change me&quot;); $(“#form-id input:checked”) .addClass(“selected”);
Now we can Select Let’s perform some  action
jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), …..
Dom Manipulation Example Move all paragraphs in div with id “contents” $(“p”) <body>  <h1>jQuery</h1> <p>jQuery is good</p> <p>jQuery is better</p> <div id=“contents”></div> <p>jQuery is the best</p> </body>
Dom Manipulation Example Move all paragraphs in div with id “contents” $(“p”).appendTo(“#contents”); <body>  <h1>jQuery</h1> <div id=“contents”> <p>jQuery is good</p> <p>jQuery is better</p> <p>jQuery is the best</p> </div> </body>
Dom Manipulation Example Move all paragraphs in div with id “contents” $(“p”).appendTo(“#contents”); $(“h1”).append(“ Dom Manipulation”); <body>  <h1>jQuery  Dom Manipulation </h1> <div id=“contents”> <p>jQuery is good</p> <p>jQuery is better</p> <p>jQuery is the best</p> </div> </body>
jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), …..
Attributes Example Make the texts of last paragraph bold $(“#contents p:last”).css(“color”, “green”); <body>  <h1>jQuery Dom Manipulation</h1> <div id=“contents”> <p >jQuery is good</p> <p>jQuery is better</p> <p  style=“color:green” >jQuery is the best</p> </div> </body>
More Attributes Example Setting $(“img.logo”) .attr(“align”, “left”); $(“p.copyright”) .html(“&copy; 2009 ajaxray”); $(“input#name”) .val(“Spiderman”);
More Attributes Example Setting $(“img.logo”) .attr(“align”, “left”); $(“p.copyright”) .html(“&copy; 2009 ajaxray”); $(“input#name”) .val(“Spiderman”);  Getting var allignment =  $(“img.logo”).attr(“align”); var copyright =  $(“p.copyright”).html(); var username =  $(“input#name”).val();
jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), ….. Events click(), bind(), unbind(), live(), …..
Event Example Start when DOM is ready $(document).ready(function(){  $( selector ). eventName ( function(){…} ); });
Event Example Bind all interactions on events. $( document ). ready (function(){  $(“ #message ”). click ( function(){ $(this).hide(); } ) });  <span id=“message” on click =“…”> blah blah </span>
Event Example You can fire events manually. $(document).ready(function(){  $(“span#message”).click(function(){ $(this).hide(); }) $(“#form-id:reset”).click(); });
jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), ….. Events click(), bind(), unbind(), live(), ….. Effects hide(), fadeOut(), toggle(), animate(), …..
Effects Example When “ show-cart ” link clicked, slide up/down “ cart ” div. $(“a#show-cart”).click(function(){ $(“#cart”) .slideToggle(“slow”); })
Effects Example Build your custom animation $(“a#show-cart”).click(function(){ $(“#cart”) .slideToggle(“slow”); }) $(&quot;#showdown&quot;).click(function(){  $(&quot;#my-div&quot;).animate({  width: &quot;70%&quot;,  opacity: 0.4,  fontSize: &quot;3em“ },  1200  );  });
jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), ….. Events click(), bind(), unbind(), live(), ….. Effects hide(), fadeOut(), toggle(), animate(), ….. Ajax load(), get(), ajax(), getJSON(), …..
Ajax Examples Load a page in a container $(“#comments”).load(“/get_comments.php”); $(“#comments”).load(“/get_comments.php”, {max : 5});
Ajax Examples Send ajax request with data $.get(“/edit_comment.php&quot;,  {id: 102, comment: “I m edited&quot;} );
Ajax Examples You can send serialized form as data $.get(“/edit_comment.php&quot;,  $(“#edit-comment”).serialize() );  id=102&comment=I+m+edited
Ajax Examples Set a callback function for handling response data $.get(“edit_comment.php&quot;,  $(“form#cmm-edit”).serialize(), function( data ){ if(data == “success”)  alert(“Comment Edited!”); } );
Chaining Methods Most jQuery methods return jQuery object You can chain them together
Chaining Methods Most jQuery methods return jQuery object You can chain them together $(“#deleted”).addClass(“red”).fadeOut(“slow”); $(“:button”).val(“Click Me”).click(function(){…})
Chaining Methods Most jQuery methods return jQuery object You can chain them together $(“#deleted”).addClass(“red”).fadeOut(“slow”); $(“:button”).val(“Click Me”).click(function(){…}) This will not work - $(“:button”). val().click(function(){…}) This method will return string
jQuery Plugins jQuery is extensible.
jQuery Plugins jQuery lightBox http://leandrovieira.com/projects/jquery/lightbox/
jQuery Plugins Slider Plugins http://www.hieu.co.uk/blog/index.php/imageswitch/   http://medienfreunde.com/lab/innerfade/
And thousands of more… http://plugins.jquery.com/
jQuery UI Build highly interactive web applications
jQuery UI – Interactions  (Draggale, Droppable, Resizable, Selectable, Sortable)
jQuery UI – Sortable Example $(&quot;#items&quot;).sortable();
jQuery UI – Widgets (Accordion, Datepicker, Dialog, Progressbar, Slider, Tabs)
jQuery UI – Datepicker Example $(&quot;#date&quot;).datepicker();
Which one will match your site?
Designing a jQuery UI theme - Themeroller http://ui.jquery.com/themeroller
Anis uddin Ahmad Sr. Software Engineer Right Brain Solution Ltd. http://ajaxray.com
Questions?
THANK YOU

More Related Content

PPT
Jquery presentation
PPTX
jQuery from the very beginning
PPTX
Jquery introduction
PDF
Your code sucks, let's fix it! - php|tek13
PPT
PDF
Dig Deeper into WordPress - WD Meetup Cairo
PPTX
jQuery PPT
PDF
jQuery Essentials
Jquery presentation
jQuery from the very beginning
Jquery introduction
Your code sucks, let's fix it! - php|tek13
Dig Deeper into WordPress - WD Meetup Cairo
jQuery PPT
jQuery Essentials

What's hot (20)

PDF
Learning jQuery in 30 minutes
PPTX
Introduction to PHP Lecture 1
PDF
Your code sucks, let's fix it - PHP Master Series 2012
PPTX
Basics of Java Script (JS)
PDF
Your code sucks, let's fix it (CakeFest2012)
PDF
Javascript
PDF
Your code sucks, let's fix it - DPC UnCon
PDF
Learn css3
PPTX
jQuery
PPTX
PDF
Disregard Inputs, Acquire Zend_Form
KEY
Geek Moot '09 -- Smarty 101
PPT
Система рендеринга в Magento
PPT
JQuery introduction
PPTX
Open Source Search: An Analysis
PPTX
Jquery-overview
PPT
J query
PPTX
J query1
PDF
Introduzione JQuery
PPTX
jQuery Fundamentals
Learning jQuery in 30 minutes
Introduction to PHP Lecture 1
Your code sucks, let's fix it - PHP Master Series 2012
Basics of Java Script (JS)
Your code sucks, let's fix it (CakeFest2012)
Javascript
Your code sucks, let's fix it - DPC UnCon
Learn css3
jQuery
Disregard Inputs, Acquire Zend_Form
Geek Moot '09 -- Smarty 101
Система рендеринга в Magento
JQuery introduction
Open Source Search: An Analysis
Jquery-overview
J query
J query1
Introduzione JQuery
jQuery Fundamentals
Ad

Viewers also liked (20)

PDF
Partitions and multi primary edition 3
PPTX
Phil 700 report
PDF
The Creative U
PPSX
Joomla
PPT
Pearl harbro
PPT
22學期永和社大2010.0531社團聯展簡報
PDF
largest and heaviest slewing bearings used in deck cranes exported to Europe
PDF
Totally Excellent Tips for Righteous Local SEO
PPTX
Pénfigo
PPTX
Projeto gelo
PPSX
CREATIVITY: Renew Your Thinking, Transform Your Life
PPTX
Shall we play a game?
PDF
Study: The Future of VR, AR and Self-Driving Cars
PDF
UX, ethnography and possibilities: for Libraries, Museums and Archives
PDF
Hype vs. Reality: The AI Explainer
PDF
Designing Teams for Emerging Challenges
PDF
Visual Design with Data
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
PDF
TEDx Manchester: AI & The Future of Work
PDF
Build Features, Not Apps
Partitions and multi primary edition 3
Phil 700 report
The Creative U
Joomla
Pearl harbro
22學期永和社大2010.0531社團聯展簡報
largest and heaviest slewing bearings used in deck cranes exported to Europe
Totally Excellent Tips for Righteous Local SEO
Pénfigo
Projeto gelo
CREATIVITY: Renew Your Thinking, Transform Your Life
Shall we play a game?
Study: The Future of VR, AR and Self-Driving Cars
UX, ethnography and possibilities: for Libraries, Museums and Archives
Hype vs. Reality: The AI Explainer
Designing Teams for Emerging Challenges
Visual Design with Data
3 Things Every Sales Team Needs to Be Thinking About in 2017
TEDx Manchester: AI & The Future of Work
Build Features, Not Apps
Ad

Similar to Jquery presentation (20)

PPTX
jQuery
PDF
jQuery Internals + Cool Stuff
PPT
PPT
jQuery Fundamentals
PPTX
jQuery Presentasion
PPT
Intro to jQuery
PPT
Introduction to JQuery
PDF
Introduction to jQuery
PPTX
Introduction to JQuery
PDF
Learning jquery-in-30-minutes-1195942580702664-3
PPTX
Web technologies-course 11.pptx
PDF
Zero to Hero, a jQuery Primer
PPT
Jquery presentation
PPTX
Jquery Complete Presentation along with Javascript Basics
PDF
PPTX
JQuery
PPTX
jQuery
PPT
J query introduction
PPTX
Iniciando com jquery
jQuery
jQuery Internals + Cool Stuff
jQuery Fundamentals
jQuery Presentasion
Intro to jQuery
Introduction to JQuery
Introduction to jQuery
Introduction to JQuery
Learning jquery-in-30-minutes-1195942580702664-3
Web technologies-course 11.pptx
Zero to Hero, a jQuery Primer
Jquery presentation
Jquery Complete Presentation along with Javascript Basics
JQuery
jQuery
J query introduction
Iniciando com jquery

Recently uploaded (20)

PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
KodekX | Application Modernization Development
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
How to Build Crypto Derivative Exchanges from Scratch.pptx
PPTX
Belt and Road Supply Chain Finance Blockchain Solution
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
Sensors and Actuators in IoT Systems using pdf
PPTX
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
Transforming Manufacturing operations through Intelligent Integrations
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KodekX | Application Modernization Development
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
GamePlan Trading System Review: Professional Trader's Honest Take
REPORT: Heating appliances market in Poland 2024
Smarter Business Operations Powered by IoT Remote Monitoring
CroxyProxy Instagram Access id login.pptx
Enable Enterprise-Ready Security on IBM i Systems.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
How to Build Crypto Derivative Exchanges from Scratch.pptx
Belt and Road Supply Chain Finance Blockchain Solution
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
NewMind AI Weekly Chronicles - August'25 Week I
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
Sensors and Actuators in IoT Systems using pdf
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
Transforming Manufacturing operations through Intelligent Integrations

Jquery presentation

  • 1.  
  • 2. What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript
  • 3. Why jQuery? Lightweight : 19KB in size (Minified and Gzipped) CSS1 - 3 Complaint Cross Browser (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome)
  • 4. Why jQuery? Lightweight : 19KB in size (Minified and Gzipped) CSS1 - 3 Complaint Cross Browser (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome) Great Community Plugins Tutorials TestCoverage Open (free) license Books
  • 5. A ajax and DOM manipulation example if (!document.ELEMENT_NODE) { document.ELEMENT_NODE = 1; document.ATTRIBUTE_NODE = 2; document.TEXT_NODE = 3; document.CDATA_SECTION_NODE = 4; document.ENTITY_REFERENCE_NODE = 5; document.ENTITY_NODE = 6; document.PROCESSING_INSTRUCTION_NODE = 7; document.COMMENT_NODE = 8; document.DOCUMENT_NODE = 9; document.DOCUMENT_TYPE_NODE = 10; document.DOCUMENT_FRAGMENT_NODE = 11; document.NOTATION_NODE = 12; } document._importNode = function(node, allChildren) { switch (node.nodeType) { case document.ELEMENT_NODE: var newNode = document.createElement(node » .nodeName); /* does the node have any attributes to add? */ if (node.attributes && node.attributes » .length > 0) for (var i = 0; il = node.attributes.length; » i < il) newNode.setAttribute(node.attributes » .nodeName, node.getAttribute(node.attributes[i++] » .nodeName)); /* are we going after children too, and does » the node have any? */ if (allChildren && node.childNodes && » node.childNodes.length > 0) for (var i = 0; il = node.childNodes.length; » i < il) newNode.appendChild(document._importNode » (node.childNodes[i++], allChildren)); return newNode; break; case document.TEXT_NODE: case document.CDATA_SECTION_NODE: case document.COMMENT_NODE: return document.createTextNode(node.nodeValue); break; } }; http:// www.alistapart.com/articles/crossbrowserscripting
  • 6. It’s just a single line in jQuery $(“#content”).load(“page.html #content”);
  • 7. Who’s using jQuery? http:// docs.jquery.com/Sites_Using_jQuery
  • 8. Dominating the world Google trends comparison of last JS framework 12 months http:// www.google.com/trends?q =jQuery%2C+prototype%2C+yui%2C+dojo%2C+mootools&ctab=0&geo= all&date = ytd&sort =0
  • 9. Let’s Start Download jQuery http:// docs.jquery.com/Downloading_jQuery
  • 10. Embed in you page <html> <head> <script src=“ path/to/jquery-x.x.js &quot;></script> </head> <body> … </body> </html>
  • 11. Embed in you page <html> <head> <script src=&quot; path/to/jquery-x.x.js &quot;></script> <script> $(document).ready(function(){ // Start here }); </script> </head> <body> … </body> </html>
  • 12. $(“div”). addClass(“xyz”); Find Some Elements Do something with them { } jQuery Object jQuery philosophy
  • 13. A Basic Example <body> <div> <p>I m a paragraph 1</p> <p>I m a paragraph 2</p> </div> <p>I m another paragraph</p> </body>
  • 14. A Basic Example <body> <div> <p>I m a paragraph 1</p> <p>I m a paragraph 2</p> </div> <p>I m another paragraph</p> </body> Select all paragraphs. $(“p”)
  • 15. A Basic Example <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> Select all paragraphs. Add a class to them. $(“p”).addClass(“red”);
  • 16. Selector Basics Just pass a selector to $() What is selector? Use any CSS selector
  • 17. Selector Basics Think about your simplest css file. #header{ margin : 0 auto; } div{ margin : 0px; padding : 0px } ul.menu li{ … .. }
  • 18. Selector Basics The red colored items are selectors #header { margin : 0 auto; } div { margin : 0px; padding : 0px } ul.menu li { … .. }
  • 19. Selector Basics Selecting By Id $(“#header”) Selecting using selectors
  • 20. Selector Basics Selecting By Id $(“#header”) Selecting By Class $(“.updated”) Selecting using selectors
  • 21. Selector Basics Selecting By Id $(“#header”) Selecting By Class $(“.updated”) Selecting by tag name $(“table”) Selecting using selectors
  • 22. Selector Basics Selecting By Id $(“#header”) Selecting By Class $(“.updated”) Selecting by tag name $(“table”) Combine them $(“table.user-list”) $(“#footer ul.menu li”) Selecting using selectors
  • 23. Basic Selector Example This is my page <body> <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
  • 24. Basic Selector Example $(“#header”) <body> <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
  • 25. Basic Selector Example $(“ul.menu”) <body> <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
  • 26. Basic Selector Example $(“ul.menu li”) <body> <div id=“header”> <span id=“logo”>Logo here…</span> <ul class=“menu”> <li>user name</li> … .. <li>logout</li> </ul> </div> …… </body>
  • 27. Using filters for selecting Basic Filters :first, :last, :even, :odd, …...
  • 28. Basic Filters Example Student list table. Lets make it zebra. Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 Mizan XII 5 Karim VI 2 Satisfactory
  • 29. Basic Filters Example $(“#students tr:even”).css(“background-color”, “#dde”) Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 Mizan XII 5 Karim VI 2 Satisfactory
  • 30. Using filters for selecting Basic Filters :first, :last, :even, :odd, …... Content Filters: :empty , :contains(text), :has(selector), …..
  • 31. Content Filters Example $(“#students tr:even”).css(“background-color”, “#dde”); $(“#students td.comment:empty”).text(“No Comment”); Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 No Comment Mizan XII 5 No Comment Karim VI 2 Satisfactory
  • 32. Using filters for selecting Basic Filters :first, :last, :even, :odd, …... Content Filters: :empty , :contains(text), :has(selector), ….. Attribute Filters: [attribute], [attribute=value], [attribute!=value], …..
  • 33. Attribute Filters Example $(“#students tr:even”).css(“background-color”, “#dde”); $(“#students td.comment:empty”).text(“No Comment”); $(“#students td[align=‘center']&quot;).addClass(“ocean”); Name Class Roll No. Comment Raju XII 2 Good Masud IX 1 Good Apu XII 3 No Comment Mizan XII 5 No Comment Karim VI 2 Satisfactory
  • 34. Using filters for selecting Basic Filters :first, :last, :even, :odd, …... Content Filters: :empty , :contains(text), :has(selector), ….. Attribute Filters: [attribute], [attribute=value], [attribute!=value], ….. Forms :input, :text, :submit, :password, ….. :enabled, :disabled, :checked, …..
  • 35. Forms Selector Example $(&quot;:submit&quot;) .click(function(e){ … }); $(&quot;input:disabled&quot;) .val(“You cannot change me&quot;); $(“#form-id input:checked”) .addClass(“selected”);
  • 36. Now we can Select Let’s perform some action
  • 37. jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), …..
  • 38. Dom Manipulation Example Move all paragraphs in div with id “contents” $(“p”) <body> <h1>jQuery</h1> <p>jQuery is good</p> <p>jQuery is better</p> <div id=“contents”></div> <p>jQuery is the best</p> </body>
  • 39. Dom Manipulation Example Move all paragraphs in div with id “contents” $(“p”).appendTo(“#contents”); <body> <h1>jQuery</h1> <div id=“contents”> <p>jQuery is good</p> <p>jQuery is better</p> <p>jQuery is the best</p> </div> </body>
  • 40. Dom Manipulation Example Move all paragraphs in div with id “contents” $(“p”).appendTo(“#contents”); $(“h1”).append(“ Dom Manipulation”); <body> <h1>jQuery Dom Manipulation </h1> <div id=“contents”> <p>jQuery is good</p> <p>jQuery is better</p> <p>jQuery is the best</p> </div> </body>
  • 41. jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), …..
  • 42. Attributes Example Make the texts of last paragraph bold $(“#contents p:last”).css(“color”, “green”); <body> <h1>jQuery Dom Manipulation</h1> <div id=“contents”> <p >jQuery is good</p> <p>jQuery is better</p> <p style=“color:green” >jQuery is the best</p> </div> </body>
  • 43. More Attributes Example Setting $(“img.logo”) .attr(“align”, “left”); $(“p.copyright”) .html(“&copy; 2009 ajaxray”); $(“input#name”) .val(“Spiderman”);
  • 44. More Attributes Example Setting $(“img.logo”) .attr(“align”, “left”); $(“p.copyright”) .html(“&copy; 2009 ajaxray”); $(“input#name”) .val(“Spiderman”); Getting var allignment = $(“img.logo”).attr(“align”); var copyright = $(“p.copyright”).html(); var username = $(“input#name”).val();
  • 45. jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), ….. Events click(), bind(), unbind(), live(), …..
  • 46. Event Example Start when DOM is ready $(document).ready(function(){ $( selector ). eventName ( function(){…} ); });
  • 47. Event Example Bind all interactions on events. $( document ). ready (function(){ $(“ #message ”). click ( function(){ $(this).hide(); } ) }); <span id=“message” on click =“…”> blah blah </span>
  • 48. Event Example You can fire events manually. $(document).ready(function(){ $(“span#message”).click(function(){ $(this).hide(); }) $(“#form-id:reset”).click(); });
  • 49. jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), ….. Events click(), bind(), unbind(), live(), ….. Effects hide(), fadeOut(), toggle(), animate(), …..
  • 50. Effects Example When “ show-cart ” link clicked, slide up/down “ cart ” div. $(“a#show-cart”).click(function(){ $(“#cart”) .slideToggle(“slow”); })
  • 51. Effects Example Build your custom animation $(“a#show-cart”).click(function(){ $(“#cart”) .slideToggle(“slow”); }) $(&quot;#showdown&quot;).click(function(){ $(&quot;#my-div&quot;).animate({ width: &quot;70%&quot;, opacity: 0.4, fontSize: &quot;3em“ }, 1200 ); });
  • 52. jQuery Methods DOM Manipulation before(), after(), append(), appendTo(), ….. Attributes css(), addClass(), attr(), html(), val(), ….. Events click(), bind(), unbind(), live(), ….. Effects hide(), fadeOut(), toggle(), animate(), ….. Ajax load(), get(), ajax(), getJSON(), …..
  • 53. Ajax Examples Load a page in a container $(“#comments”).load(“/get_comments.php”); $(“#comments”).load(“/get_comments.php”, {max : 5});
  • 54. Ajax Examples Send ajax request with data $.get(“/edit_comment.php&quot;, {id: 102, comment: “I m edited&quot;} );
  • 55. Ajax Examples You can send serialized form as data $.get(“/edit_comment.php&quot;, $(“#edit-comment”).serialize() ); id=102&comment=I+m+edited
  • 56. Ajax Examples Set a callback function for handling response data $.get(“edit_comment.php&quot;, $(“form#cmm-edit”).serialize(), function( data ){ if(data == “success”) alert(“Comment Edited!”); } );
  • 57. Chaining Methods Most jQuery methods return jQuery object You can chain them together
  • 58. Chaining Methods Most jQuery methods return jQuery object You can chain them together $(“#deleted”).addClass(“red”).fadeOut(“slow”); $(“:button”).val(“Click Me”).click(function(){…})
  • 59. Chaining Methods Most jQuery methods return jQuery object You can chain them together $(“#deleted”).addClass(“red”).fadeOut(“slow”); $(“:button”).val(“Click Me”).click(function(){…}) This will not work - $(“:button”). val().click(function(){…}) This method will return string
  • 60. jQuery Plugins jQuery is extensible.
  • 61. jQuery Plugins jQuery lightBox http://leandrovieira.com/projects/jquery/lightbox/
  • 62. jQuery Plugins Slider Plugins http://www.hieu.co.uk/blog/index.php/imageswitch/ http://medienfreunde.com/lab/innerfade/
  • 63. And thousands of more… http://plugins.jquery.com/
  • 64. jQuery UI Build highly interactive web applications
  • 65. jQuery UI – Interactions (Draggale, Droppable, Resizable, Selectable, Sortable)
  • 66. jQuery UI – Sortable Example $(&quot;#items&quot;).sortable();
  • 67. jQuery UI – Widgets (Accordion, Datepicker, Dialog, Progressbar, Slider, Tabs)
  • 68. jQuery UI – Datepicker Example $(&quot;#date&quot;).datepicker();
  • 69. Which one will match your site?
  • 70. Designing a jQuery UI theme - Themeroller http://ui.jquery.com/themeroller
  • 71. Anis uddin Ahmad Sr. Software Engineer Right Brain Solution Ltd. http://ajaxray.com