SlideShare uma empresa Scribd logo
1 de 21
By mishraDileep
Agenda
 Introduction, Prerequisite    jQuery Filters
 What is jQuery?               jQuery Attributes
 What is available with        jQuery Events
  jQuery?                       jQuery Callback Functions
 How to use jQuery?            jQuery HTML Manipulation
 jQuery Syntax                 jQuery CSS Manipulation
 jQuery Selectors
Introduction & Prerequisites
 A JavaScript library
 Easy to learn and implement
 jQuery is a fast and concise JavaScript Library that simplifies
    HTML document traversing
    Event handling
    Animation
    AJAX Interaction for rapid web development


 Prerequisites
    HTML
    CSS
    JavaScript
What is jQuery?
 A library of JavaScript Functions.
 A lightweight "write less, do more" JavaScript library.
 The jQuery library contains the following features:
         HTML element selections
         HTML element manipulation
         CSS manipulation
         HTML event functions
         JavaScript Effects and animations
         HTML DOM traversal and modification
         AJAX
         Utilities

 An open source project, maintained by group of developers
  with active support base and well written documentation
What is available with jQuery
 Cross Browser support     JavaScript Animation
 AJAX Functions            Hundreds of plug-ins for
 CSS functions              pre-built user interfaces,
                             advanced animation and
 DOM Manipulation
                             form validation etc …
 DOM Traversing
                            Expandable using custom
 Attribute Manipulation     plug-ins
 Event detection and       Small footprint
 handling
How to use jQuery?
 A single JavaScript file, containing all the jQuery methods.

 Add the following code into your html/jsp page and call the jQuery APIs.
          <head>
           <script type="text/javascript" src="jquery.js"></script>
           </head>
 For Example
          <html>
           <head>
           <script type="text/javascript" src="jquery.js"></script>
           <script type="text/javascript">
           $(document).ready(function(){
            $("button").click(function(){
               $("p").hide();
            });
           });
           </script>
           </head>
           <body>
           <h2>This is a heading</h2>
           <p>This is a paragraph.</p>
           <p>This is another paragraph.</p>
           <button>Click me</button>
           </body>
           </html>
How to use jQuery?Cont…
 In order to use jQuery you need to load it.
 You can include it locally on your own server:
    <script src="/js/jquery.js">
 Or use one of the CDN's made available:
    ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
    ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js
    CDN's are Gzipped and minified
jQuery Syntax
 With jQuery you select (query) HTML elements and
  perform "actions" on them.
 jQuery Syntax Examples
      $(this).hide()
      $("#test").hide()
      $("p").hide()
      $(".test").hide()

 Basic syntax is: $(selector).action()
    A dollar sign to define jQuery
    A (selector) to "query (or find)" HTML elements
    A jQuery action() to be performed on the element(s)
jQuery Selectors
 To select HTML elements (or groups of elements) by
  element name, attribute name or by content.

 jQuery Element Selectors
    Uses CSS selectors to select HTML elements.
       $("p“)
       $("p.intro“)
       $("p#demo“)
jQuery Selectors
 jQuery Attribute Selectors
    jQuery uses XPath expressions to select elements with given
     attributes.
    $("[href ]“)
    $("[href='#']")
    $("[href!='#']“).
    $("[href$='.jpg']“)
 jQuery CSS Selectors
    jQuery CSS selectors can be used to change CSS properties for
     HTML elements.
    For Ex :
        $("p").css("background-color","yellow");
jQuery Selectors
 Few samples for the selectors
Syntax                Description
$(this)               Current HTML element
$("p")                All <p> elements
$("p.intro")          All <p> elements with class="intro"
$(".intro")           All elements with class="intro"
$("#intro")           The first element with id="intro"
$("ul li:first")      The first <li> element of each <ul>
$("[href$='.jpg']")   All elements with an href attribute that ends with ".jpg"
$("div#intro          All elements with class="head" inside a <div> element with
.head")               id="intro"
jQuery Filters
 First paragraph – p:first
 Last list item – li:last
 Fourth link – a:nth(3)
 Fourth Div – div:eq(3)
 Every other Paragraph – p:odd or p:even
 Every link after/upto 4th – a:gt(3) or a:lt(4)
 Links that contain word like click – a:contains(“click”)
 All radio inputs with in first form - $(“input:radio”,
  documents.forms[0])
jQuery Attributes
 Read
    $(#image).attr(“src”);
 Set
    $(#image).attr(“src” , “images/jquery1.jpg”);
 Multiple Set
    $(#image).attr({src: “images/jquery1.jpg” , alt: “jQuery”});
 Set Class
    $(p:last).addClass(“selected”);
 Read/Set Html
    $(#id).html() & $(#id).html(“value”);
jQuery Events
 The jQuery event handling methods are core functions in jQuery.

 For Example
       <html>
        <head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){
         $("button").click(function(){
            $("p").hide();
         });
        });
        </script>
        </head>
        <body>
        <h2>This is a heading</h2>
        <p>This is a paragraph.</p>
        <p>This is another paragraph.</p>
        <button>Click me</button>
        </body></html>
jQuery Callback Functions
 A callback function is executed after the current
  animation (effect) is finished.
 Syntax
   $(selector).hide(speed,callback)
 For Ex:
    $("p").hide(1000,function(){
      alert("The paragraph is now hidden");
     });
jQuery HTML Manipulation
 jQuery can manipulate the HTML elements and
  attributes
 Changing HTML Content
   $(selector).html(content)
 Adding HTML content
    $(selector).append(content)
    $(selector).prepend(content)
    $(selector).after(content)
    $(selector).before(content)
jQuery HTML Manipulation
  jQuery HTML Manipulation Methods

Function                      Description

$(selector).html(content)     Changes the (inner) HTML of selected elements

                              Appends content to the (inner) HTML of selected
$(selector).append(content)
                              elements

$(selector).after(content)    Adds HTML after selected elements
jQuery CSS Manipulation
 jQuery css() Method
    css(name) - Return CSS property value
    css(name,value) - Set CSS property and value
    css({properties}) - Set multiple CSS properties and values
 Examples
    Return CSS Property
        $(this).css("background-color");
    Set CSS Property & value
      $("p").css("background-color"," yellow");
    Set Multiple values in CSS
      $("p").css({"background-color":"yellow","font-size":"200%"});
    Size Manipulation
      $("#div1").height("200px"); $("#div2").width("300px");
jQuery CSS Manipulation
 Offset
   $(this).offset().left
   $(this).offset().top


 Position
    $(this).position().left
    $(this).position().top
jQuery CSS Manipulation
 jQuery CSS Manipulation Methods
CSS Properties                  Description

                                Get the style property value of the first
$(selector).css(name)
                                matched element

                                Set the value of one style property for
$(selector).css(name,value)
                                matched elements

                                Set multiple style properties for
$(selector).css({properties})
                                matched elements

$(selector).height(value)       Set the height of matched elements
$(selector).width(value)        Set the width of matched elements
jQuery

Mais conteúdo relacionado

Mais procurados (20)

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 |...
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
 
jQuery
jQueryjQuery
jQuery
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Java script
Java scriptJava script
Java script
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Js ppt
Js pptJs ppt
Js ppt
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Operators php
Operators phpOperators php
Operators php
 

Destaque

Destaque (6)

jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Jqueryppt (1)
Jqueryppt (1)Jqueryppt (1)
Jqueryppt (1)
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 

Semelhante a 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 BasicsEPAM Systems
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue AdventureAllegient
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQueryorestJump
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuerykolkatageeks
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQueryAlan Hecht
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxazz71
 
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
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Rakesh Jha
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationMevin Mohan
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerySeble Nigussie
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012ghnash
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryGunjan Kumar
 

Semelhante a jQuery (20)

J query training
J query trainingJ query training
J query training
 
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
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
jQuery
jQueryjQuery
jQuery
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
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...
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
 
Jquery
JqueryJquery
Jquery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
J query
J queryJ query
J query
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 

Último

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Último (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

jQuery

  • 2. Agenda  Introduction, Prerequisite  jQuery Filters  What is jQuery?  jQuery Attributes  What is available with  jQuery Events jQuery?  jQuery Callback Functions  How to use jQuery?  jQuery HTML Manipulation  jQuery Syntax  jQuery CSS Manipulation  jQuery Selectors
  • 3. Introduction & Prerequisites  A JavaScript library  Easy to learn and implement  jQuery is a fast and concise JavaScript Library that simplifies  HTML document traversing  Event handling  Animation  AJAX Interaction for rapid web development  Prerequisites  HTML  CSS  JavaScript
  • 4. What is jQuery?  A library of JavaScript Functions.  A lightweight "write less, do more" JavaScript library.  The jQuery library contains the following features:  HTML element selections  HTML element manipulation  CSS manipulation  HTML event functions  JavaScript Effects and animations  HTML DOM traversal and modification  AJAX  Utilities  An open source project, maintained by group of developers with active support base and well written documentation
  • 5. What is available with jQuery  Cross Browser support  JavaScript Animation  AJAX Functions  Hundreds of plug-ins for  CSS functions pre-built user interfaces, advanced animation and  DOM Manipulation form validation etc …  DOM Traversing  Expandable using custom  Attribute Manipulation plug-ins  Event detection and  Small footprint handling
  • 6. How to use jQuery?  A single JavaScript file, containing all the jQuery methods.  Add the following code into your html/jsp page and call the jQuery APIs.  <head> <script type="text/javascript" src="jquery.js"></script> </head>  For Example  <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button> </body> </html>
  • 7. How to use jQuery?Cont…  In order to use jQuery you need to load it.  You can include it locally on your own server:  <script src="/js/jquery.js">  Or use one of the CDN's made available:  ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js  ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js  CDN's are Gzipped and minified
  • 8. jQuery Syntax  With jQuery you select (query) HTML elements and perform "actions" on them.  jQuery Syntax Examples  $(this).hide()  $("#test").hide()  $("p").hide()  $(".test").hide()  Basic syntax is: $(selector).action()  A dollar sign to define jQuery  A (selector) to "query (or find)" HTML elements  A jQuery action() to be performed on the element(s)
  • 9. jQuery Selectors  To select HTML elements (or groups of elements) by element name, attribute name or by content.  jQuery Element Selectors  Uses CSS selectors to select HTML elements.  $("p“)  $("p.intro“)  $("p#demo“)
  • 10. jQuery Selectors  jQuery Attribute Selectors  jQuery uses XPath expressions to select elements with given attributes.  $("[href ]“)  $("[href='#']")  $("[href!='#']“).  $("[href$='.jpg']“)  jQuery CSS Selectors  jQuery CSS selectors can be used to change CSS properties for HTML elements.  For Ex :  $("p").css("background-color","yellow");
  • 11. jQuery Selectors  Few samples for the selectors Syntax Description $(this) Current HTML element $("p") All <p> elements $("p.intro") All <p> elements with class="intro" $(".intro") All elements with class="intro" $("#intro") The first element with id="intro" $("ul li:first") The first <li> element of each <ul> $("[href$='.jpg']") All elements with an href attribute that ends with ".jpg" $("div#intro All elements with class="head" inside a <div> element with .head") id="intro"
  • 12. jQuery Filters  First paragraph – p:first  Last list item – li:last  Fourth link – a:nth(3)  Fourth Div – div:eq(3)  Every other Paragraph – p:odd or p:even  Every link after/upto 4th – a:gt(3) or a:lt(4)  Links that contain word like click – a:contains(“click”)  All radio inputs with in first form - $(“input:radio”, documents.forms[0])
  • 13. jQuery Attributes  Read  $(#image).attr(“src”);  Set  $(#image).attr(“src” , “images/jquery1.jpg”);  Multiple Set  $(#image).attr({src: “images/jquery1.jpg” , alt: “jQuery”});  Set Class  $(p:last).addClass(“selected”);  Read/Set Html  $(#id).html() & $(#id).html(“value”);
  • 14. jQuery Events  The jQuery event handling methods are core functions in jQuery.  For Example  <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); </script> </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button> </body></html>
  • 15. jQuery Callback Functions  A callback function is executed after the current animation (effect) is finished.  Syntax  $(selector).hide(speed,callback)  For Ex:  $("p").hide(1000,function(){ alert("The paragraph is now hidden"); });
  • 16. jQuery HTML Manipulation  jQuery can manipulate the HTML elements and attributes  Changing HTML Content  $(selector).html(content)  Adding HTML content  $(selector).append(content)  $(selector).prepend(content)  $(selector).after(content)  $(selector).before(content)
  • 17. jQuery HTML Manipulation  jQuery HTML Manipulation Methods Function Description $(selector).html(content) Changes the (inner) HTML of selected elements Appends content to the (inner) HTML of selected $(selector).append(content) elements $(selector).after(content) Adds HTML after selected elements
  • 18. jQuery CSS Manipulation  jQuery css() Method  css(name) - Return CSS property value  css(name,value) - Set CSS property and value  css({properties}) - Set multiple CSS properties and values  Examples  Return CSS Property  $(this).css("background-color");  Set CSS Property & value  $("p").css("background-color"," yellow");  Set Multiple values in CSS  $("p").css({"background-color":"yellow","font-size":"200%"});  Size Manipulation  $("#div1").height("200px"); $("#div2").width("300px");
  • 19. jQuery CSS Manipulation  Offset  $(this).offset().left  $(this).offset().top  Position  $(this).position().left  $(this).position().top
  • 20. jQuery CSS Manipulation  jQuery CSS Manipulation Methods CSS Properties Description Get the style property value of the first $(selector).css(name) matched element Set the value of one style property for $(selector).css(name,value) matched elements Set multiple style properties for $(selector).css({properties}) matched elements $(selector).height(value) Set the height of matched elements $(selector).width(value) Set the width of matched elements