SlideShare a Scribd company logo
Nikhil Kumar
Software Consultant
Knoldus Software LLP
Nikhil Kumar
Software Consultant
Knoldus Software LLP
Agenda
● Introduction of jQuery
● What is jQuery
● Getting started with jQuery
● Animation, Callback, Chaining
● DOM Manipulation, GET, SET, ADD, REMOVE
● DOM Traversing
● Managing events, contents and effects
Introduction to jQuery
“Jquery is easy
&
very useful”
Introduction to jQuery
●
jQuery is a lightweight, "write less, do more", 
JavaScript library.
●
Query is a fast, small, and feature­rich 
JavaScript library. 
●
It makes things like HTML document traversal 
and manipulation, event handling, animation, 
and Ajax much simpler.
Adding jQuery to a page
<script src="../dist/jquery-2.1.4.min.js"></script>
<script type="text/javascript”>
$(document).ready(function() {
Your code here…
});
</script>
Adding jQuery to a page
You might have noticed that all jQuery methods in our examples, are 
inside a document ready event:
$(document).ready(function(){
   // jQuery methods go here...
});
This is to prevent any jQuery code from running before the document is 
finished loading (is ready).
    Trying to hide an element that is not created yet
    Trying to get the size of an image that is not loaded yet
 $(function(){
   // jQuery methods go here...
});
Using Selector with jQuery
●
 In order to start manipulating an HTML page 
dynamically you first need to locate the desired 
items.
●
Id and Class
$('h1') //selects all h1 elements
$('.class-name') //selects all elements
with class of class-name
$('#id') //selects element with an id of ID
Attribute based selector
● To find elements in which an attribute is set to a
specific value, you use the equality syntax.
● Note that the value you wish to compare must be in
quotes.
// selects **all** elements that contains this attribute
$('[“href"]')
// selects all **h1** elements with an attribute matching the
specified value
$('h1[demo-attribute="demo-value"]')
More selectors
Attribute based selector cont...
● jQuery allows you to select items by searching inside of
attribute values for desired sub-strings.
● If you wish to find all elements where the value starts with a
string, use the ^= operator.
● If you wish to find all elements where the value contains a
string, use the *= operator.
$('[class^=”col”]') //selects all elements start with 'col'
$('[class*=”md”]') //selects all elements contain 'md'
Positional Selectors
●
Oftentimes you need to located elements based on where they are on the
page, or in relation to other elements in the DOM.
●
For example, an <a> element inside of a <nav> section may need to be
treated differently than <a> elements elsewhere on the page. CSS, and in turn
jQuery, offer the ability to find items based on their location.
● The > between selectors indicates the parent/child relationship.
$('nav > a') //Selects all <a> elements that are direct
//descendants nav element
$('nav a') //Selects all <a> elements that are
//descendants nav element The elements can
//appear anywhere inside of the element
//listed first
Adding/Removing classes
●
jQuery also makes it very easy to manipulate the classes an element is currently using.
●
In fact, you'll notice most libraries that use jQuery to manipulate the UI will also come with a
stylesheet that defines the set of classes their code will use to enable the functionality.
●
Adding a class to an element is just as easy as calling addClass.
●
Removing a class from an element is just as easy as calling removeClass.
var currentElement = $('#demo');
currentElement.addClass('class-name') //Add class
//'class-name' to selected element.
currentElement.removeClass('class-name') //removes class
//'class-name' from selected element.
Working with attributes
● To retrieve an attribute value, simply use the attr method with one parameter, the
name of the attribute you wish to retrieve.
● To update an attribute value, use the attr method with two parameters, the first being
the name of the attribute and the second the new value you wish to use.
var attribute = $('selector').attr('attribute-name');
//gets value of the attribute 'attribute-name' of 'selector'
$('selector').attr('attribute-name','new-value');
//changes value of the attribute 'attribute-name' to 'new-value'
//of 'selector'
Modifying Content
● Beyond just working with classes and attributes,
jQuery allows you to modify the content of an
element as well.
// update the text
$('selector').text('Hello, world!!');
// update the HTML
$('selector').html('Hello, world!!');
Event Handlers
●
jQuery provides several ways to register an event handler.
●
The term "fires/fired" is often used with events. Example: "The 
keypress event is fired, the moment you press a key".
●
 Mouse Events & Form Events etc
Basic event handlers
●
To register an event handler, you will call the jQuery 
method that matches the event handler you're looking for.
// click event
// raised when the item is clicked
$('selector').click(function() {
alert('clicked!!');
});
// hover event
// raised when the user moves their mouse over the item
$('selector').hover(function() {
alert('hover!!');
});
Some useful events
●
We have some useful events
– Click
– Double Click
– Blur
– Change
– Focus
– Mouse Enter and Mouse Leave
– Hover
 Event Example
$("p").on({
    mouseenter: function(){
        $(this).css("background­color", "lightgray");
    },
    mouseleave: function(){
        $(this).css("background­color", "lightblue");
    },
    click: function(){
        $(this).css("background­color", "yellow");
    }
});
Jquery Effects
   Hide, Show, Toggle, Slide, Fade, and Animate. WOW!
Toggle
         $("button").click(function(){
             $("p").toggle();
         });
Animate       
         $("button").click(function(){
             $("div").animate({left: '250px'}); 
        });         
Callback Functions
A callback function ensures you that it will execute  after 
completing the previous action.
●
Syntax
$(selector).hide(speed,callback);
Example
       $("button").click(function(){
           $("p").hide("slow", function(){
               alert("The paragraph is now hidden");
            }); 
        });
                                                                                                    *Write without callback
Chaining
●
Chaining allows multiple events, actions etc to run in one 
go.
Example
      
        $("#p1").css("color", "red")
            .slideUp(2000)
            .slideDown(2000);
DOM Manipulation
– Get, Set, Add, Remove, Css, dimensions etc
Get Content:
Three methods:
● text() - Sets or returns the text content of selected elements
● html() - Sets or returns the content of selected elements (including HTML markup)
● val() - Sets or returns the value of form fields
&
● Attr()
Example
$("#btn1").click(function(){
alert("Value: " + $("#test").val());
});
Example : attr()
● Complete this example
$("button").click(function(){
alert($("#id").attr("href"));
});
Dom Manipulation
● Set Content:
$(document).ready(function(){
    $("#btn1").click(function(){
        $("#test1").text("Hello world!");
    });
    $("#btn2").click(function(){
        $("#test2").html("<b>Hello world!</b>");
    });
    $("#btn3").click(function(){
        $("#test3").val("Dolly Duck");
    });
});
Dom Manipulation
ADD:
Majorly 4 methods:
● append() - Inserts content at the end of the selected elements
● prepend() - Inserts content at the beginning of the selected elements
● after() - Inserts content after the selected elements
● before() - Inserts content before the selected elements
● Examples
● $("p").append("Some appended text.");
● $("img").after("Some text after");
function afterText() {
var txt1 = "<b>I </b>"; // Create element with HTML
var txt2 = $("<i></i>").text("love "); // Create with jQuery
var txt3 = document.createElement("b"); // Create with DOM
txt3.innerHTML = "jQuery!";
$("img").after(txt1, txt2, txt3); // Insert new elements after <img>
}
Dom Manipulation
● Remove
● $("div").remove(".test, .demo");
//remove app “div” that contains .test & .demo class
● Empty
● $("#div1").empty();
Dom Manipulation
● addClass() - Adds one or more classes to the selected elements
● removeClass() - Removes one or more classes from the selected
elements
● toggleClass() - Toggles between adding/removing classes from the
selected elements
● css() - Sets or returns the style attribute
● -Make Example for each
$("button").click(function(){
alert("Background= " + $("p").css("background-color"));
});
Jquery Traversing
● The <div> element is the parent of <ul>, and an ancestor of everything inside of it
● The <ul> element is the parent of both <li> elements, and a child of <div>
● The left <li> element is the parent of <span>, child of <ul> and a descendant of <div>
● The <span> element is a child of the left <li> and a descendant of <ul> and <div>
● The two <li> elements are siblings (they share the same parent)
● The right <li> element is the parent of <b>, child of <ul> and a descendant of <div>
● The <b> element is a child of the right <li> and a descendant of <ul> and <div>
Thank You !!Thank You !!
References:
1- jquery official documentation
2- Jquery communities
3- w3schools

More Related Content

ODP
Unit Testing and Coverage for AngularJS
PDF
AngularJS Unit Test
PPT
Testing in AngularJS
PDF
Intro to Unit Testing in AngularJS
PDF
AngularJS Unit Testing w/Karma and Jasmine
PDF
Angular testing
PDF
Angularjs - Unit testing introduction
ODP
Angular JS Unit Testing - Overview
Unit Testing and Coverage for AngularJS
AngularJS Unit Test
Testing in AngularJS
Intro to Unit Testing in AngularJS
AngularJS Unit Testing w/Karma and Jasmine
Angular testing
Angularjs - Unit testing introduction
Angular JS Unit Testing - Overview

What's hot (20)

PDF
Test-Driven Development of AngularJS Applications
PDF
Intro to JavaScript
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
PPTX
AngularJS Unit Testing
PDF
Intro to testing Javascript with jasmine
PPTX
Angular Unit Testing
PPTX
Angular Unit Testing
PPTX
Unit testing in JavaScript with Jasmine and Karma
PDF
JavaScript TDD with Jasmine and Karma
PDF
Quick tour to front end unit testing using jasmine
PDF
Automated Testing in Angular Slides
PDF
Client side unit tests - using jasmine & karma
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
Unit Testing Express and Koa Middleware in ES2015
PDF
Nicolas Embleton, Advanced Angular JS
PDF
Painless JavaScript Testing with Jest
PPTX
Full Stack Unit Testing
PDF
Dart for Java Developers
PDF
Angular Unit Testing NDC Minn 2018
PDF
How AngularJS Embraced Traditional Design Patterns
Test-Driven Development of AngularJS Applications
Intro to JavaScript
Unit testing of java script and angularjs application using Karma Jasmine Fra...
AngularJS Unit Testing
Intro to testing Javascript with jasmine
Angular Unit Testing
Angular Unit Testing
Unit testing in JavaScript with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Quick tour to front end unit testing using jasmine
Automated Testing in Angular Slides
Client side unit tests - using jasmine & karma
Advanced Jasmine - Front-End JavaScript Unit Testing
Unit Testing Express and Koa Middleware in ES2015
Nicolas Embleton, Advanced Angular JS
Painless JavaScript Testing with Jest
Full Stack Unit Testing
Dart for Java Developers
Angular Unit Testing NDC Minn 2018
How AngularJS Embraced Traditional Design Patterns
Ad

Similar to Jquery- One slide completing all JQuery (20)

PPTX
Jquery Complete Presentation along with Javascript Basics
PPTX
How to increase Performance of Web Application using JQuery
PPTX
JQuery_and_Ajax.pptx
PDF
Jquery tutorial-beginners
PDF
PDF
jQuery -Chapter 2 - Selectors and Events
PPTX
Jquery Basics
PDF
Introducing jQuery
PPTX
Unit3.pptx
PPTX
UNIT 1 (7).pptx
PPTX
PDF
Learning jQuery made exciting in an interactive session by one of our team me...
PPTX
jQuery
PPTX
PPTX
Jquery
PPTX
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Jquery Complete Presentation along with Javascript Basics
How to increase Performance of Web Application using JQuery
JQuery_and_Ajax.pptx
Jquery tutorial-beginners
jQuery -Chapter 2 - Selectors and Events
Jquery Basics
Introducing jQuery
Unit3.pptx
UNIT 1 (7).pptx
Learning jQuery made exciting in an interactive session by one of our team me...
jQuery
Jquery
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Java 17 features and implementation.pptx
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Java 17 features and implementation.pptx
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.

Recently uploaded (20)

PDF
SEVA- Fashion designing-Presentation.pdf
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
PDF
Chalkpiece Annual Report from 2019 To 2025
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PDF
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
PPTX
6- Architecture design complete (1).pptx
PPTX
EDP Competencies-types, process, explanation
PPTX
CLASSIFICATION OF YARN- process, explanation
PPTX
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
PPTX
mahatma gandhi bus terminal in india Case Study.pptx
PPTX
Entrepreneur intro, origin, process, method
PPTX
joggers park landscape assignment bandra
PDF
Quality Control Management for RMG, Level- 4, Certificate
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PDF
Interior Structure and Construction A1 NGYANQI
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PPTX
building Planning Overview for step wise design.pptx
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
SEVA- Fashion designing-Presentation.pdf
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
Chalkpiece Annual Report from 2019 To 2025
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
6- Architecture design complete (1).pptx
EDP Competencies-types, process, explanation
CLASSIFICATION OF YARN- process, explanation
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
mahatma gandhi bus terminal in india Case Study.pptx
Entrepreneur intro, origin, process, method
joggers park landscape assignment bandra
Quality Control Management for RMG, Level- 4, Certificate
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
Interior Structure and Construction A1 NGYANQI
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
building Planning Overview for step wise design.pptx
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...

Jquery- One slide completing all JQuery

Editor's Notes

  • #10: Many frameworks, such as Bootstrap, make their magic happen by having developers add certain classes or other attributes to their HTML. Often, the values you&amp;apos;ll use for classes or attributes have consistent patterns or prefixes. jQuery allows you to select items by searching inside of attribute values for desired sub-strings.
  • #11: For example, an a element inside of a nav section may need to be treated differently than a elements elsewhere on the page. CSS, and in turn jQuery, offer the ability to find items based on their location. $(&amp;apos;nav &amp;gt; a&amp;apos;) &amp;lt;nav&amp;gt; &amp;lt;a href=”#”&amp;gt;(First) This will be selected&amp;lt;/a&amp;gt; &amp;lt;div&amp;gt; &amp;lt;a href=”#”&amp;gt;(Second) This will **not** be selected&amp;lt;/a&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;/nav&amp;gt;
  • #14: jQuery offers you the ability to update the text inside of an element by using the text method, and the HTML inside of an element by using the html method. Both methods will replace all of the content of an element. The main difference between the two methods is html will update (and parse) the HTML that&amp;apos;s passed into the method, while text will be text only. If you pass markup into the text method, it will be HTML encoded, meaning all tags will be converted into the appropriate syntax to just display text, rather than markup. In other words, &amp;lt; will become &amp;lt; and just display as &amp;lt; in the browser. By using text when you&amp;apos;re only expecting text, you can mitigate cross-site scripting attacks.
  • #15: Web pages are typically built using an event based architecture. An event is something that occurs where we, as the developer, don&amp;apos;t have direct control over its timing. Unlike a classic console application, where you provide a list of options to the user, in a time and order that you choose, a web page presents the user with a set of controls, such as buttons and textboxes, that the user can typically click around on whenever they see fit. As a result, being able to manage what happens when an event occurs is critical. Fortunately, in case you hadn&amp;apos;t already guessed, jQuery provides a robust API for registering and managing event handlers, which is the code that will be executed when an event is raised. Event handlers are, at the end of the day, simply JavaScript functions.
  • #16: To register an event handler, you will call the jQuery method that matches the event handler you&amp;apos;re looking for. For example, if you wanted the click event, you&amp;apos;d use the click method. Methods for wiring up event handlers allow you to pass either an existing function, or create an anonymous method. Most developers prefer to use an anonymous method, as it makes it easier to keep the namespace clean and not have to name another item. Inside of the event handler code, you can access the object that raised the event by using this. One important note about this is it is not a jQuery object but rather a DOM object; you can convert it by using the jQuery constructor as we&amp;apos;ve seen before: $(this)