SlideShare a Scribd company logo
1 of 83
Download to read offline
jQuery.essentials();
Made with by @elacheche_bedis
- What is it?
- Why should I use it?
- How to use it?
- What is it?
- Why should I use it?
- How to use it?
What is
- Cross-platform Javascript library.
- Designed to simplify the client-side scripting of
HTML.
- Allows you to easily select elements and
manipulate or add some behaviour on them.
- It's basically more accessible Javascript.
- What is it?
- Why should I use it?
- How to use it?
Why should I use
- Free
- Open-source
- Large online community to help :
• Forums
• Blogs
• Tutorials
• IRC (#jquery on freenode)
• Books
- Extensively documented and tested
- Normalises many cross-browser quirks so don’t have to worry about them
Why should I use
var XMLHttpFactories = [
function() { return new XMLHttpRequest() },
function() { return new ActiveXObject("Msxml2.XMLHTTP") },
function() { return new ActiveXObject("Msxml3.XMLHTTP") },
function() { return new ActiveXObject("Microsoft.XMLHTTP") }
];
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i = 0; i < XMLHttpFactories.length; i++) {
try {
xmlhttp = XMLHttpFactories[i]();
} catch (e) {
continue;
}
break;
}
return xmlhttp;
}
Javascript cross-browser ajax request :
Why should I use
function sendRequest(url, callback, postData) {
var req = createXMLHTTPObject();
if (!req) return;
var method = (postData) ? "POST" : "GET";
req.open(method, url, true);
req.setRequestHeader('UserPAgent', 'XMLHTTP/1.0');
if (postData) {
req.setRequestHeader('ContentPtype',
'application/xPwwwPformPurlencoded');
}
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
return;
}
callback(req);
}
if (req.readyState == 4) return;
req.send(postData);
}
Javascript cross-browser ajax request :
Why should I use
// Get data
$.get('slides.php', {
From : 1 ,
to : 5
},function(data) {  
$('.result').html(data);
});
jQuery cross-browser ajax request :
- What is it?
- Why should I use it?
- How to use it?
How to use : Getting started
www.jquery.com
How to use : Getting started
<html>
<head>
<title>Hello jQuery</title>
</head>
<body>
<script src="jquery-1.11.3.min.js"></script>
</body>
</html>
Include jQuery using a <script> tag
How to use : Getting started
<html>
<head>
<title>Hello jQuery</title>
</head>
<body>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</body>
</html>
Alternatively, you can load it from a CDN*
* Content Delivery Network
How to use : Getting started
<html>
<head>
<title>Hello jQuery</title>
</head>
<body>
<script src="jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// your code should go here
});
</script>
</body>
</html>
In most cases, your code should run when the document has finished loading.
How to use : Getting started
<script type="text/javascript">
jQuery(document).ready(function(){
//your code should go here
});
</script>
$ is an alias to jQuery
Code can either use $ or just jQuery :
<script type="text/javascript">
$(document).ready(function(){
//your code should go here
});
</script>
jQuery.selectors();
How to use : Selectors
//Basic selectors
// ID
$('#presentation')
// class
$('.slide')  
// element
$('div')
//wildcard
$('*')
//attribute
$('input[name="prezName"]')
<div class="welcome"></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<input type="text" name="prezName"/>
How to use : Selectors
//Basic selectors
// ID
$('#presentation')
// class
$('.slide')  
// element
$('div')
//wildcard
$('*')
//attribute
$('input[name="prezName"]')
<div class="welcome"></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<input type="text" name="prezName"/>
How to use : Selectors
//Basic selectors
// ID
$('#presentation')
// class
$('.slide')  
// element
$('div')
//wildcard
$('*')
//attribute
$('input[name="prezName"]')
<div class="welcome"></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<input type="text" name="prezName"/>
How to use : Selectors
//Basic selectors
// ID
$('#presentation')
// class
$('.slide')  
// element
$('div')
//wildcard
$('*')
//attribute
$('input[name="prezName"]')
<div class="welcome"></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<input type="text" name="prezName"/>
How to use : Selectors
//Basic selectors
// ID
$('#presentation')
// class
$('.slide')  
// element
$('div')
//wildcard
$('*')
//attribute
$('input[name="prezName"]')
<div class="welcome"></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<input type="text" name="prezName"/>
How to use : Selectors
//Basic selectors
// ID
$('#presentation')
// class
$('.slide')  
// element
$('div')
//wildcard
$('*')
//attribute
$('input[name="prezName"]')
<div class="welcome"></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<input type="text" name="prezName"/>
How to use : Selectors
// Parent/child selectors
    
// returns children of the parent a
$('ul li')
    
// returns elements that are a child
// element of a
$('body > ul')
    
// returns the elements that are
// adjacent to the selector
$('ul + input')
    
// returns ul elements that are a
// sibling of p
$('div ~ ul')
<div class="welcome"><ul></ul></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<ul></ul>
<input type="text" name="prezName"/>
How to use : Selectors
// Parent/child selectors
    
// returns children of the parent a
$('ul li')
    
// returns elements that are a child
// element of a
$('body > ul')
    
// returns the elements that are
// adjacent to the selector
$('ul + input')
    
// returns ul elements that are a
// sibling of p
$('div ~ ul')
<div class="welcome"><ul></ul></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<ul></ul>
<input type="text" name="prezName"/>
How to use : Selectors
// Parent/child selectors
    
// returns children of the parent a
$('ul li')
    
// returns elements that are a child
// element of a
$('body > ul')
    
// returns the elements that are
// adjacent to the selector
$('ul + input')
    
// returns ul elements that are a
// sibling of p
$('div ~ ul')
<div class="welcome"><ul></ul></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<ul></ul>
<input type="text" name="prezName"/>
How to use : Selectors
// Parent/child selectors
    
// returns children of the parent a
$('ul li')
    
// returns elements that are a child
// element of a
$('body > ul')
    
// returns the elements that are
// adjacent to the selector
$('ul + input')
    
// returns ul elements that are a
// sibling of p
$('div ~ ul')
<div class="welcome"><ul></ul></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<ul></ul>
<input type="text" name="prezName"/>
How to use : Selectors
// Parent/child selectors
    
// returns children of the parent a
$('ul li')
    
// returns elements that are a child
// element of a
$('body > ul')
    
// returns the elements that are
// adjacent to the selector
$('ul + input')
    
// returns ul elements that are a
// sibling of p
$('div ~ ul')
<div class="welcome"><ul></ul></div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
<ul></ul>
<input type="text" name="prezName"/>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//first element in a result set
$('ul li:first')
    
//first child of the parent
$('ul li:first-child')
    
//last element in a result set
$('ul li:last')
    
//last child of the parent
$('ul li:last-child')
//all odd elements in a result set
$('ul li:odd')
    
//all even elements in a result set
$('ul li:even')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// nth-child filters
    
// nth child in a result set
$('ul li:nth-child(2)')
 
// all odd numbered results
$('ul li:nth-child(odd)')
    
// all even numbered results
$('ul li:nth-child(even)')
    
// all elements based on a formula.
// here it’s every 2nd child
$('ul li:nth-child(2n)')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// nth-child filters
    
// nth child in a result set
$('ul li:nth-child(2)')
 
// all odd numbered results
$('ul li:nth-child(odd)')
    
// all even numbered results
$('ul li:nth-child(even)')
    
// all elements based on a formula.
// here it’s every 2nd child
$('ul li:nth-child(2n)')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// nth-child filters
    
// nth child in a result set
$('ul li:nth-child(2)')
 
// all odd numbered results
$('ul li:nth-child(odd)')
    
// all even numbered results
$('ul li:nth-child(even)')
    
// all elements based on a formula.
// here it’s every 2nd child
$('ul li:nth-child(2n)')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// nth-child filters
    
// nth child in a result set
$('ul li:nth-child(2)')
 
// all odd numbered results
$('ul li:nth-child(odd)')
    
// all even numbered results
$('ul li:nth-child(even)')
    
// all elements based on a formula.
// here it’s every 2nd child
$('ul li:nth-child(2n)')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// nth-child filters
    
// nth child in a result set
$('ul li:nth-child(2)')
 
// all odd numbered results
$('ul li:nth-child(odd)')
    
// all even numbered results
$('ul li:nth-child(even)')
    
// all elements based on a formula.
// here it’s every 2nd child
$('ul li:nth-child(2n)')
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// returns elements that are equal to
// the index supplied
$('ul li:eq(1)')
    
// returns elements that are greather
// than the index supplied
$('ul li:gt(2)')
    
// returns elements in a set less
// than the index supplied
$('ul li:lt(2)')
// returns elements that are hidden
$('li:hidden')
    
// returns elements that are visible
$('li:visible')
<style type="text/css">
.gone{ display:none}
</style>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide gone">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// returns elements that are equal to
// the index supplied
$('ul li:eq(1)')
    
// returns elements that are greather
// than the index supplied
$('ul li:gt(2)')
    
// returns elements in a set less
// than the index supplied
$('ul li:lt(2)')
// returns elements that are hidden
$('li:hidden')
    
// returns elements that are visible
$('li:visible')
<style type="text/css">
.gone{ display:none}
</style>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide gone">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// returns elements that are equal to
// the index supplied
$('ul li:eq(1)')
    
// returns elements that are greather
// than the index supplied
$('ul li:gt(2)')
    
// returns elements in a set less
// than the index supplied
$('ul li:lt(2)')
// returns elements that are hidden
$('li:hidden')
    
// returns elements that are visible
$('li:visible')
<style type="text/css">
.gone{ display:none}
</style>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide gone">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// returns elements that are equal to
// the index supplied
$('ul li:eq(1)')
    
// returns elements that are greather
// than the index supplied
$('ul li:gt(2)')
    
// returns elements in a set less
// than the index supplied
$('ul li:lt(2)')
// returns elements that are hidden
$('li:hidden')
    
// returns elements that are visible
$('li:visible')
<style type="text/css">
.gone{ display:none}
</style>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide gone">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// returns elements that are equal to
// the index supplied
$('ul li:eq(1)')
    
// returns elements that are greather
// than the index supplied
$('ul li:gt(2)')
    
// returns elements in a set less
// than the index supplied
$('ul li:lt(2)')
// returns elements that are hidden
$('li:hidden')
    
// returns elements that are visible
$('li:visible')
<style type="text/css">
.gone{ display:none}
</style>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide gone">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
// returns elements that are equal to
// the index supplied
$('ul li:eq(1)')
    
// returns elements that are greather
// than the index supplied
$('ul li:gt(2)')
    
// returns elements in a set less
// than the index supplied
$('ul li:lt(2)')
// returns elements that are hidden
$('li:hidden')
    
// returns elements that are visible
$('li:visible')
<style type="text/css">
.gone{ display:none}
</style>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide gone">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//form filters
    
//returns elements that are enabled
$('input:enabled')
    
//returns elements that are disabled
$('input:disabled')
    
//returns checked items 
$(':checked')
 
// returns elements that don't match
// the condition supplied  
$('input:not(:checked)')
//returns selected items
$('select option:selected')
<div class="welcome"></div>
<input type="text" name="prezName"/>
<input disabled=”disabled” type="text"
name="prezDescription"/>
<input type="checkbox" checked="checked"/>
<select name="currentSlide">
    <option>Selectors</option>
    <option selected="selected">
Filters
</option>
</select>
<input type="checkbox"/>
How to use : Filters
//form filters
    
//returns elements that are enabled
$('input:enabled')
    
//returns elements that are disabled
$('input:disabled')
    
//returns checked items 
$(':checked')
 
// returns elements that don't match
// the condition supplied  
$('input:not(:checked)')
//returns selected items
$('select option:selected')
<div class="welcome"></div>
<input type="text" name="prezName"/>
<input disabled=”disabled” type="text"
name="prezDescription"/>
<input type="checkbox" checked="checked"/>
<select name="currentSlide">
    <option>Selectors</option>
    <option selected="selected">
Filters
</option>
</select>
<input type="checkbox"/>
How to use : Filters
//form filters
    
//returns elements that are enabled
$('input:enabled')
    
//returns elements that are disabled
$('input:disabled')
    
//returns checked items 
$(':checked')
 
// returns elements that don't match
// the condition supplied  
$('input:not(:checked)')
//returns selected items
$('select option:selected')
<div class="welcome"></div>
<input type="text" name="prezName"/>
<input disabled=”disabled” type="text"
name="prezDescription"/>
<input type="checkbox" checked="checked"/>
<select name="currentSlide">
    <option>Selectors</option>
    <option selected="selected">
Filters
</option>
</select>
<input type="checkbox"/>
How to use : Filters
//form filters
    
//returns elements that are enabled
$('input:enabled')
    
//returns elements that are disabled
$('input:disabled')
    
//returns checked items 
$(':checked')
 
// returns elements that don't match
// the condition supplied  
$('input:not(:checked)')
//returns selected items
$('select option:selected')
<div class="welcome"></div>
<input type="text" name="prezName"/>
<input disabled=”disabled” type="text"
name="prezDescription"/>
<input type="checkbox" checked="checked"/>
<select name="currentSlide">
    <option>Selectors</option>
    <option selected="selected">
Filters
</option>
</select>
<input type="checkbox"/>
How to use : Filters
//form filters
    
//returns elements that are enabled
$('input:enabled')
    
//returns elements that are disabled
$('input:disabled')
    
//returns checked items 
$(':checked')
 
// returns elements that don't match
// the condition supplied  
$('input:not(:checked)')
//returns selected items
$('select option:selected')
<div class="welcome"></div>
<input type="text" name="prezName"/>
<input disabled=”disabled” type="text"
name="prezDescription"/>
<input type="checkbox" checked="checked"/>
<select name="currentSlide">
    <option>Selectors</option>
    <option selected="selected">
Filters
</option>
</select>
<input type="checkbox"/>
How to use : Filters
//form filters
    
//returns elements that are enabled
$('input:enabled')
    
//returns elements that are disabled
$('input:disabled')
    
//returns checked items 
$(':checked')
 
// returns elements that don't match
// the condition supplied  
$('input:not(:checked)')
//returns selected items
$('select option:selected')
<div class="welcome"></div>
<input type="text" name="prezName"/>
<input disabled=”disabled” type="text"
name="prezDescription"/>
<input type="checkbox" checked="checked"/>
<select name="currentSlide">
    <option>Selectors</option>
    <option selected="selected">
Filters
</option>
</select>
<input type="checkbox"/>
How to use : Filters
//content filters
    
// :has(x) all elements with a
// descendant that matches x
$('div:has(p)')
                   
//:contains(x) the element contains x
$('li:contains("Ajax")')
    
//returns elements that are empty
$(':empty')
  
//returns the parent of li  
$('li:parent')
<div class="welcome">
<p></p>
</div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//content filters
    
// :has(x) all elements with a
// descendant that matches x
$('div:has(p)')
                   
//:contains(x) the element contains x
$('li:contains("Ajax")')
    
//returns elements that are empty
$(':empty')
  
//returns the parent of li  
$('li:parent')
<div class="welcome">
<p></p>
</div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//content filters
    
// :has(x) all elements with a
// descendant that matches x
$('div:has(p)')
                   
//:contains(x) the element contains x
$('li:contains("Ajax")')
    
//returns elements that are empty
$(':empty')
  
//returns the parent of li  
$('li:parent')
<div class="welcome">
<p></p>
</div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//content filters
    
// :has(x) all elements with a
// descendant that matches x
$('div:has(p)')
                   
//:contains(x) the element contains x
$('li:contains("Ajax")')
    
//returns elements that are empty
$(':empty')
  
//returns the parent of li  
$('li:parent')
<div class="welcome">
<p></p>
</div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Filters
//content filters
    
// :has(x) all elements with a
// descendant that matches x
$('div:has(p)')
                   
//:contains(x) the element contains x
$('li:contains("Ajax")')
    
//returns elements that are empty
$(':empty')
  
//returns the parent of li  
$('li:parent')
<div class="welcome">
<p></p>
</div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
How to use : Collections
// this returns a jQuery collection
// your selection wrapped inside a 
// jQuery object that can be further
// manipulated
$('ul li')
    
// we can treat it a little like an
array
$('ul li').length //4
    
// we can iterate over it..
$('ul li').each(function(i, x){
    console.log(i, $(this).text()); 
});
// and we can also call methods on it
$('ul li').hide();
<div class="welcome">
<p></p>
</div>
<ul id="presentation">
    <li class="slide">Getting started</li>
    <li class="slide">Selectors</li>
    <li class="slide">Filters</li>
    <li class="slide"></li>
    <li class="slide">Ajax</li>
</ul>
Understanding what $() returns
jQuery.chaining();
How to use : Chaining
 $('ul')
    .find('.slide')
    .addClass('active');
 $('ul')
    .find('.slide')
    .removeClass('pending');
 
$('ul')
    .find('.slide')
    .addClass('active')
    .removeClass('pending');
Chaining method calls to write shorter, less repetitive code
When you call a method on a jQuery object another jQuery object is usually returned
jQuery.caching();
How to use : Caching
// uncached selections
$('.slide').fadeIn();
$('.slide').css('color','blue');
$('.slide').on('click',function(){
    console.log('hello jQuery');
});
// cache the selection
var slides = $('.slide');
// use as needed
slides.fadeIn();
slides.css('color','blue');
slides.on('click', function(){
    console.log('hello jQuery');
});
How to avoid re-querying the DOM unless absolutely necessary
How to use : Caching
// uncached selections
$('.slide').fadeIn();
$('.slide').css('color','blue');
$('.slide').on('click',function(){
    console.log('hello jQuery');
});
// this also supports chaining!
var slides = $('.slide');
slides
    .fadeIn()
    .css('color','blue')
    .on('click', function(){
        console.log('hello jQuery');
    });
How to avoid re-querying the DOM unless absolutely necessary
jQuery.attributes();
How to use : Attributes
// gets the value of an attribute
// for the first element in a set only
var link = $('a').attr('href');
console.log(link); // www.google.com
// sets the value of an attribute
$('a').attr('href','www.jquery.com');
// we can also set multiple
// attributes at the same time
$('a').attr({
    title: 'jQuery!',
    href: 'http://google.com'
});
<a href='www.google.com'>
Click me !
</a>
<a href='#'>
Another link
</a>
<a href='#'>
Just another link
</a>
Getting and settings DOM attributes of elements
jQuery.properties();
How to use : Properties
var elem = $('input[type=checkbox]');
console.log(elem.prop('checked'));
//true
console.log(elem.is(':checked'));
//true
// change property
elem.prop('checked','');
//or
elem.removeProp('checked');
<a href='#'>
Another link
</a>
<a href='#'>
Just another link
</a>
<input type='checkbox' checked/>
Getting and settings DOM properties of elements
jQuery.data();
How to use : Data
var last = $('.slide:last');
// Set some data
last.data('description', 'Summarizes content');
// You can then access this data
// as follows:
console.log(last.data('description')); // Summarizes content
Storing and retrieving arbitrary data using specific DOM elements
– Can be used to store data in key/value pairs
– Data is stored against any DOM elements
<ul>
<li class='slide'>CSS</li>
<li class='slide'>AJAX</li>
<li class='slide'>Summary</li>
</ul>
How to use : Data
var last = $('.slide:last');
// Set some data
last.data('description', 'Summarizes content');
// You can then access this data
// as follows:
console.log(last.data('description')); // Summarizes content
Storing and retrieving arbitrary data using specific DOM elements
– Can be used to store data in key/value pairs
– Data is stored against any DOM elements
<ul>
<li class='slide'>CSS</li>
<li class='slide'>AJAX</li>
<li class='slide' data-description='Summarizes content'>Summary</li>
</ul>
jQuery.css();
How to use : CSS
// Gets a CSS property
var bgColor = $('.slide').css('backgroundColor');
console.log(bgColor); //gray
// Sets a CSS property
$('.slide').css('backgroundColor','blue');
// Sets multiple CSS properties
$('.slide').css({
'width':'1600',
'height':'900',
'color':'blue',
'backgroundColor':'gray'
});
Methods for getting and setting CSS-related properties of elements
How to use : CSS
$('.slide:first').addClass('visible');
$('.slide:first').removeClass('pending');
$('.slide').toggleClass('visible');
Supports some other utility methods :
<li class="slide pending">
CSS
</li>
<li class="slide pending">
AJAX
</li>
How to use : CSS
$('.slide:first').addClass('visible');
$('.slide:first').removeClass('pending');
$('.slide').toggleClass('visible');
Supports some other utility methods :
<li class="slide pending visible">
CSS
</li>
<li class="slide pending">
AJAX
</li>
How to use : CSS
$('.slide:first').addClass('visible');
$('.slide:first').removeClass('pending');
$('.slide').toggleClass('visible');
Supports some other utility methods :
<li class="slide visible">
CSS
</li>
<li class="slide pending">
AJAX
</li>
How to use : CSS
$('.slide:first').addClass('visible');
$('.slide:first').removeClass('pending');
$('.slide').toggleClass('visible');
Supports some other utility methods :
<li class="slide">
CSS
</li>
<li class="slide pending visible">
AJAX
</li>
jQuery.events();
How to use : Events
Registering behaviours which are applied when a user interacts with the browser :
// Binding a click event to elements
// with the class 'slide'
$('.slide').on('click', function(){
    $(this).css('color','red'); 
});
// Remove just the click event handler
$('.slide').off('click','**');
// Remove all event handlers from slides
$('.slide').off();
How to use : Events
Other jQuery events methods:
- $(elem).load(function(e){ ... });
- $(elem).unload(function(e){ ... });
- $(elem).click(function(e){ ... });
- $(elem).dblclick(function(e){ ... });
- $(elem).hover(function(e){ ... });
- $(elem).blur(function(e){ ... });
- $(elem).focus(function(e){ ... });
- $(elem).change(function(e){ ... });
- $(elem).keydown(function(e){ ... });
- $(elem).keyup(function(e){ ... });
- $(elem).resize(function(e){ ... });
- $(elem).scroll(function(e){ ... });
- $(elem).submit(function(e){ ... });
How to use : Ajax
Supports both short and long-hand methods for making Ajax requests
Cross-browser XHR without the headaches!
Performing asynchronous HTTP requests
jQuery.ajax();
How to use : Ajax
// Retrieve the latest version of a web page
$.ajax({  
url: "slides.html",
type: 'GET', // (POST | PUT | DELETE | ..)
dataType: 'html', // (xml | json | script | ..)
cache: false,
data : { from : 1 , to : 5 },
beforeSend: function(xhr){
// Pre-request callback
},
// What to do if this is successful:
success: function(html) {   
$("#results").append(html);  
},
// What to do if this fails:
error: function() {      
//something went wrong
}
});
How to use : Ajax
// Get data
$.get('slides.html', function(data) {  
$('.result').html(data);
});
// Post data
$.post('slides.php', {
name: 'AJAX'
},  function(data) {  
$('.result').html(data);
});
// Get JSON data
$.getJSON('slides.json', function(data) {  
console.log(data);
});
// Load a JavaScript file
$.getScript('slides.js', function(data) {
console.log(data);
});
$('thanks').sayTo('you');
Made with by @elacheche_bedis

More Related Content

What's hot

Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesHùng Nguyễn Huy
 
Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11Katy Slemon
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web ComponentsFu Cheng
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingHaim Michael
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXLRob Gietema
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular ComponentsSquash Apps Pvt Ltd
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafThymeleaf
 
Oracle apex training
Oracle apex trainingOracle apex training
Oracle apex trainingVasudha India
 

What's hot (20)

Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Advanced angular
Advanced angularAdvanced angular
Advanced angular
 
Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11Step by Step Guide on Lazy Loading in Angular 11
Step by Step Guide on Lazy Loading in Angular 11
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Vue.js for beginners
Vue.js for beginnersVue.js for beginners
Vue.js for beginners
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Express node js
Express node jsExpress node js
Express node js
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
 
Oracle alert
Oracle alertOracle alert
Oracle alert
 
Oracle apex training
Oracle apex trainingOracle apex training
Oracle apex training
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 

Similar to jQuery Essentials

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
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Alessandro Nadalin
 
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
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerySeble Nigussie
 
Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018Elliot Taylor
 
ChocolateChip-UI
ChocolateChip-UIChocolateChip-UI
ChocolateChip-UIGeorgeIshak
 
Railsbridge javascript
Railsbridge   javascriptRailsbridge   javascript
Railsbridge javascriptp4geoff
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeLaurence Svekis ✔
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneRafael Felix da Silva
 
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Phil Leggetter
 
HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010alanburke
 
Zero to Hero, a jQuery Primer
Zero to Hero, a jQuery PrimerZero to Hero, a jQuery Primer
Zero to Hero, a jQuery PrimerMatthew Buchanan
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJSEdi Santoso
 

Similar to jQuery Essentials (20)

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 quick tuts
jQuery quick tutsjQuery quick tuts
jQuery quick tuts
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
 
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
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
iWebkit
iWebkitiWebkit
iWebkit
 
Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018Building scalable products with WordPress - WordCamp London 2018
Building scalable products with WordPress - WordCamp London 2018
 
J query training
J query trainingJ query training
J query training
 
ChocolateChip-UI
ChocolateChip-UIChocolateChip-UI
ChocolateChip-UI
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 
Railsbridge javascript
Railsbridge   javascriptRailsbridge   javascript
Railsbridge javascript
 
JQuery
JQueryJQuery
JQuery
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
 
HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010
 
Zero to Hero, a jQuery Primer
Zero to Hero, a jQuery PrimerZero to Hero, a jQuery Primer
Zero to Hero, a jQuery Primer
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
 

More from Bedis ElAchèche

Have we forgotten how to program? - Tunisian WebDev MeetUp
Have we forgotten how to program? - Tunisian WebDev MeetUpHave we forgotten how to program? - Tunisian WebDev MeetUp
Have we forgotten how to program? - Tunisian WebDev MeetUpBedis ElAchèche
 
Communication entre android et arduino via bluetooth
Communication entre android et arduino via bluetoothCommunication entre android et arduino via bluetooth
Communication entre android et arduino via bluetoothBedis ElAchèche
 

More from Bedis ElAchèche (6)

Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
The dark side of IA
The dark side of IAThe dark side of IA
The dark side of IA
 
Have we forgotten how to program? - Tunisian WebDev MeetUp
Have we forgotten how to program? - Tunisian WebDev MeetUpHave we forgotten how to program? - Tunisian WebDev MeetUp
Have we forgotten how to program? - Tunisian WebDev MeetUp
 
Node.js essentials
 Node.js essentials Node.js essentials
Node.js essentials
 
SVN essentials
SVN essentialsSVN essentials
SVN essentials
 
Communication entre android et arduino via bluetooth
Communication entre android et arduino via bluetoothCommunication entre android et arduino via bluetooth
Communication entre android et arduino via bluetooth
 

Recently uploaded

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
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

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...
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

jQuery Essentials

  • 2. - What is it? - Why should I use it? - How to use it?
  • 3. - What is it? - Why should I use it? - How to use it?
  • 4. What is - Cross-platform Javascript library. - Designed to simplify the client-side scripting of HTML. - Allows you to easily select elements and manipulate or add some behaviour on them. - It's basically more accessible Javascript.
  • 5. - What is it? - Why should I use it? - How to use it?
  • 6. Why should I use - Free - Open-source - Large online community to help : • Forums • Blogs • Tutorials • IRC (#jquery on freenode) • Books - Extensively documented and tested - Normalises many cross-browser quirks so don’t have to worry about them
  • 7. Why should I use var XMLHttpFactories = [ function() { return new XMLHttpRequest() }, function() { return new ActiveXObject("Msxml2.XMLHTTP") }, function() { return new ActiveXObject("Msxml3.XMLHTTP") }, function() { return new ActiveXObject("Microsoft.XMLHTTP") } ]; function createXMLHTTPObject() { var xmlhttp = false; for (var i = 0; i < XMLHttpFactories.length; i++) { try { xmlhttp = XMLHttpFactories[i](); } catch (e) { continue; } break; } return xmlhttp; } Javascript cross-browser ajax request :
  • 8. Why should I use function sendRequest(url, callback, postData) { var req = createXMLHTTPObject(); if (!req) return; var method = (postData) ? "POST" : "GET"; req.open(method, url, true); req.setRequestHeader('UserPAgent', 'XMLHTTP/1.0'); if (postData) { req.setRequestHeader('ContentPtype', 'application/xPwwwPformPurlencoded'); } req.onreadystatechange = function() { if (req.readyState != 4) return; if (req.status != 200 && req.status != 304) { return; } callback(req); } if (req.readyState == 4) return; req.send(postData); } Javascript cross-browser ajax request :
  • 9. Why should I use // Get data $.get('slides.php', { From : 1 , to : 5 },function(data) {   $('.result').html(data); }); jQuery cross-browser ajax request :
  • 10. - What is it? - Why should I use it? - How to use it?
  • 11. How to use : Getting started www.jquery.com
  • 12. How to use : Getting started <html> <head> <title>Hello jQuery</title> </head> <body> <script src="jquery-1.11.3.min.js"></script> </body> </html> Include jQuery using a <script> tag
  • 13. How to use : Getting started <html> <head> <title>Hello jQuery</title> </head> <body> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> </body> </html> Alternatively, you can load it from a CDN* * Content Delivery Network
  • 14. How to use : Getting started <html> <head> <title>Hello jQuery</title> </head> <body> <script src="jquery-1.11.3.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ // your code should go here }); </script> </body> </html> In most cases, your code should run when the document has finished loading.
  • 15. How to use : Getting started <script type="text/javascript"> jQuery(document).ready(function(){ //your code should go here }); </script> $ is an alias to jQuery Code can either use $ or just jQuery : <script type="text/javascript"> $(document).ready(function(){ //your code should go here }); </script>
  • 17. How to use : Selectors //Basic selectors // ID $('#presentation') // class $('.slide')   // element $('div') //wildcard $('*') //attribute $('input[name="prezName"]') <div class="welcome"></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <input type="text" name="prezName"/>
  • 18. How to use : Selectors //Basic selectors // ID $('#presentation') // class $('.slide')   // element $('div') //wildcard $('*') //attribute $('input[name="prezName"]') <div class="welcome"></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <input type="text" name="prezName"/>
  • 19. How to use : Selectors //Basic selectors // ID $('#presentation') // class $('.slide')   // element $('div') //wildcard $('*') //attribute $('input[name="prezName"]') <div class="welcome"></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <input type="text" name="prezName"/>
  • 20. How to use : Selectors //Basic selectors // ID $('#presentation') // class $('.slide')   // element $('div') //wildcard $('*') //attribute $('input[name="prezName"]') <div class="welcome"></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <input type="text" name="prezName"/>
  • 21. How to use : Selectors //Basic selectors // ID $('#presentation') // class $('.slide')   // element $('div') //wildcard $('*') //attribute $('input[name="prezName"]') <div class="welcome"></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <input type="text" name="prezName"/>
  • 22. How to use : Selectors //Basic selectors // ID $('#presentation') // class $('.slide')   // element $('div') //wildcard $('*') //attribute $('input[name="prezName"]') <div class="welcome"></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <input type="text" name="prezName"/>
  • 23. How to use : Selectors // Parent/child selectors      // returns children of the parent a $('ul li')      // returns elements that are a child // element of a $('body > ul')      // returns the elements that are // adjacent to the selector $('ul + input')      // returns ul elements that are a // sibling of p $('div ~ ul') <div class="welcome"><ul></ul></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <ul></ul> <input type="text" name="prezName"/>
  • 24. How to use : Selectors // Parent/child selectors      // returns children of the parent a $('ul li')      // returns elements that are a child // element of a $('body > ul')      // returns the elements that are // adjacent to the selector $('ul + input')      // returns ul elements that are a // sibling of p $('div ~ ul') <div class="welcome"><ul></ul></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <ul></ul> <input type="text" name="prezName"/>
  • 25. How to use : Selectors // Parent/child selectors      // returns children of the parent a $('ul li')      // returns elements that are a child // element of a $('body > ul')      // returns the elements that are // adjacent to the selector $('ul + input')      // returns ul elements that are a // sibling of p $('div ~ ul') <div class="welcome"><ul></ul></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <ul></ul> <input type="text" name="prezName"/>
  • 26. How to use : Selectors // Parent/child selectors      // returns children of the parent a $('ul li')      // returns elements that are a child // element of a $('body > ul')      // returns the elements that are // adjacent to the selector $('ul + input')      // returns ul elements that are a // sibling of p $('div ~ ul') <div class="welcome"><ul></ul></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <ul></ul> <input type="text" name="prezName"/>
  • 27. How to use : Selectors // Parent/child selectors      // returns children of the parent a $('ul li')      // returns elements that are a child // element of a $('body > ul')      // returns the elements that are // adjacent to the selector $('ul + input')      // returns ul elements that are a // sibling of p $('div ~ ul') <div class="welcome"><ul></ul></div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> <ul></ul> <input type="text" name="prezName"/>
  • 28. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 29. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 30. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 31. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 32. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 33. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 34. How to use : Filters //first element in a result set $('ul li:first')      //first child of the parent $('ul li:first-child')      //last element in a result set $('ul li:last')      //last child of the parent $('ul li:last-child') //all odd elements in a result set $('ul li:odd')      //all even elements in a result set $('ul li:even') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 35. How to use : Filters // nth-child filters      // nth child in a result set $('ul li:nth-child(2)')   // all odd numbered results $('ul li:nth-child(odd)')      // all even numbered results $('ul li:nth-child(even)')      // all elements based on a formula. // here it’s every 2nd child $('ul li:nth-child(2n)') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 36. How to use : Filters // nth-child filters      // nth child in a result set $('ul li:nth-child(2)')   // all odd numbered results $('ul li:nth-child(odd)')      // all even numbered results $('ul li:nth-child(even)')      // all elements based on a formula. // here it’s every 2nd child $('ul li:nth-child(2n)') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 37. How to use : Filters // nth-child filters      // nth child in a result set $('ul li:nth-child(2)')   // all odd numbered results $('ul li:nth-child(odd)')      // all even numbered results $('ul li:nth-child(even)')      // all elements based on a formula. // here it’s every 2nd child $('ul li:nth-child(2n)') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 38. How to use : Filters // nth-child filters      // nth child in a result set $('ul li:nth-child(2)')   // all odd numbered results $('ul li:nth-child(odd)')      // all even numbered results $('ul li:nth-child(even)')      // all elements based on a formula. // here it’s every 2nd child $('ul li:nth-child(2n)') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 39. How to use : Filters // nth-child filters      // nth child in a result set $('ul li:nth-child(2)')   // all odd numbered results $('ul li:nth-child(odd)')      // all even numbered results $('ul li:nth-child(even)')      // all elements based on a formula. // here it’s every 2nd child $('ul li:nth-child(2n)') <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 40. How to use : Filters // returns elements that are equal to // the index supplied $('ul li:eq(1)')      // returns elements that are greather // than the index supplied $('ul li:gt(2)')      // returns elements in a set less // than the index supplied $('ul li:lt(2)') // returns elements that are hidden $('li:hidden')      // returns elements that are visible $('li:visible') <style type="text/css"> .gone{ display:none} </style> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide gone">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 41. How to use : Filters // returns elements that are equal to // the index supplied $('ul li:eq(1)')      // returns elements that are greather // than the index supplied $('ul li:gt(2)')      // returns elements in a set less // than the index supplied $('ul li:lt(2)') // returns elements that are hidden $('li:hidden')      // returns elements that are visible $('li:visible') <style type="text/css"> .gone{ display:none} </style> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide gone">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 42. How to use : Filters // returns elements that are equal to // the index supplied $('ul li:eq(1)')      // returns elements that are greather // than the index supplied $('ul li:gt(2)')      // returns elements in a set less // than the index supplied $('ul li:lt(2)') // returns elements that are hidden $('li:hidden')      // returns elements that are visible $('li:visible') <style type="text/css"> .gone{ display:none} </style> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide gone">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 43. How to use : Filters // returns elements that are equal to // the index supplied $('ul li:eq(1)')      // returns elements that are greather // than the index supplied $('ul li:gt(2)')      // returns elements in a set less // than the index supplied $('ul li:lt(2)') // returns elements that are hidden $('li:hidden')      // returns elements that are visible $('li:visible') <style type="text/css"> .gone{ display:none} </style> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide gone">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 44. How to use : Filters // returns elements that are equal to // the index supplied $('ul li:eq(1)')      // returns elements that are greather // than the index supplied $('ul li:gt(2)')      // returns elements in a set less // than the index supplied $('ul li:lt(2)') // returns elements that are hidden $('li:hidden')      // returns elements that are visible $('li:visible') <style type="text/css"> .gone{ display:none} </style> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide gone">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 45. How to use : Filters // returns elements that are equal to // the index supplied $('ul li:eq(1)')      // returns elements that are greather // than the index supplied $('ul li:gt(2)')      // returns elements in a set less // than the index supplied $('ul li:lt(2)') // returns elements that are hidden $('li:hidden')      // returns elements that are visible $('li:visible') <style type="text/css"> .gone{ display:none} </style> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide gone">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 46. How to use : Filters //form filters      //returns elements that are enabled $('input:enabled')      //returns elements that are disabled $('input:disabled')      //returns checked items  $(':checked')   // returns elements that don't match // the condition supplied   $('input:not(:checked)') //returns selected items $('select option:selected') <div class="welcome"></div> <input type="text" name="prezName"/> <input disabled=”disabled” type="text" name="prezDescription"/> <input type="checkbox" checked="checked"/> <select name="currentSlide">     <option>Selectors</option>     <option selected="selected"> Filters </option> </select> <input type="checkbox"/>
  • 47. How to use : Filters //form filters      //returns elements that are enabled $('input:enabled')      //returns elements that are disabled $('input:disabled')      //returns checked items  $(':checked')   // returns elements that don't match // the condition supplied   $('input:not(:checked)') //returns selected items $('select option:selected') <div class="welcome"></div> <input type="text" name="prezName"/> <input disabled=”disabled” type="text" name="prezDescription"/> <input type="checkbox" checked="checked"/> <select name="currentSlide">     <option>Selectors</option>     <option selected="selected"> Filters </option> </select> <input type="checkbox"/>
  • 48. How to use : Filters //form filters      //returns elements that are enabled $('input:enabled')      //returns elements that are disabled $('input:disabled')      //returns checked items  $(':checked')   // returns elements that don't match // the condition supplied   $('input:not(:checked)') //returns selected items $('select option:selected') <div class="welcome"></div> <input type="text" name="prezName"/> <input disabled=”disabled” type="text" name="prezDescription"/> <input type="checkbox" checked="checked"/> <select name="currentSlide">     <option>Selectors</option>     <option selected="selected"> Filters </option> </select> <input type="checkbox"/>
  • 49. How to use : Filters //form filters      //returns elements that are enabled $('input:enabled')      //returns elements that are disabled $('input:disabled')      //returns checked items  $(':checked')   // returns elements that don't match // the condition supplied   $('input:not(:checked)') //returns selected items $('select option:selected') <div class="welcome"></div> <input type="text" name="prezName"/> <input disabled=”disabled” type="text" name="prezDescription"/> <input type="checkbox" checked="checked"/> <select name="currentSlide">     <option>Selectors</option>     <option selected="selected"> Filters </option> </select> <input type="checkbox"/>
  • 50. How to use : Filters //form filters      //returns elements that are enabled $('input:enabled')      //returns elements that are disabled $('input:disabled')      //returns checked items  $(':checked')   // returns elements that don't match // the condition supplied   $('input:not(:checked)') //returns selected items $('select option:selected') <div class="welcome"></div> <input type="text" name="prezName"/> <input disabled=”disabled” type="text" name="prezDescription"/> <input type="checkbox" checked="checked"/> <select name="currentSlide">     <option>Selectors</option>     <option selected="selected"> Filters </option> </select> <input type="checkbox"/>
  • 51. How to use : Filters //form filters      //returns elements that are enabled $('input:enabled')      //returns elements that are disabled $('input:disabled')      //returns checked items  $(':checked')   // returns elements that don't match // the condition supplied   $('input:not(:checked)') //returns selected items $('select option:selected') <div class="welcome"></div> <input type="text" name="prezName"/> <input disabled=”disabled” type="text" name="prezDescription"/> <input type="checkbox" checked="checked"/> <select name="currentSlide">     <option>Selectors</option>     <option selected="selected"> Filters </option> </select> <input type="checkbox"/>
  • 52. How to use : Filters //content filters      // :has(x) all elements with a // descendant that matches x $('div:has(p)')                     //:contains(x) the element contains x $('li:contains("Ajax")')      //returns elements that are empty $(':empty')    //returns the parent of li   $('li:parent') <div class="welcome"> <p></p> </div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 53. How to use : Filters //content filters      // :has(x) all elements with a // descendant that matches x $('div:has(p)')                     //:contains(x) the element contains x $('li:contains("Ajax")')      //returns elements that are empty $(':empty')    //returns the parent of li   $('li:parent') <div class="welcome"> <p></p> </div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 54. How to use : Filters //content filters      // :has(x) all elements with a // descendant that matches x $('div:has(p)')                     //:contains(x) the element contains x $('li:contains("Ajax")')      //returns elements that are empty $(':empty')    //returns the parent of li   $('li:parent') <div class="welcome"> <p></p> </div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 55. How to use : Filters //content filters      // :has(x) all elements with a // descendant that matches x $('div:has(p)')                     //:contains(x) the element contains x $('li:contains("Ajax")')      //returns elements that are empty $(':empty')    //returns the parent of li   $('li:parent') <div class="welcome"> <p></p> </div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 56. How to use : Filters //content filters      // :has(x) all elements with a // descendant that matches x $('div:has(p)')                     //:contains(x) the element contains x $('li:contains("Ajax")')      //returns elements that are empty $(':empty')    //returns the parent of li   $('li:parent') <div class="welcome"> <p></p> </div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul>
  • 57. How to use : Collections // this returns a jQuery collection // your selection wrapped inside a  // jQuery object that can be further // manipulated $('ul li')      // we can treat it a little like an array $('ul li').length //4      // we can iterate over it.. $('ul li').each(function(i, x){     console.log(i, $(this).text());  }); // and we can also call methods on it $('ul li').hide(); <div class="welcome"> <p></p> </div> <ul id="presentation">     <li class="slide">Getting started</li>     <li class="slide">Selectors</li>     <li class="slide">Filters</li>     <li class="slide"></li>     <li class="slide">Ajax</li> </ul> Understanding what $() returns
  • 59. How to use : Chaining  $('ul')     .find('.slide')     .addClass('active');  $('ul')     .find('.slide')     .removeClass('pending');   $('ul')     .find('.slide')     .addClass('active')     .removeClass('pending'); Chaining method calls to write shorter, less repetitive code When you call a method on a jQuery object another jQuery object is usually returned
  • 61. How to use : Caching // uncached selections $('.slide').fadeIn(); $('.slide').css('color','blue'); $('.slide').on('click',function(){     console.log('hello jQuery'); }); // cache the selection var slides = $('.slide'); // use as needed slides.fadeIn(); slides.css('color','blue'); slides.on('click', function(){     console.log('hello jQuery'); }); How to avoid re-querying the DOM unless absolutely necessary
  • 62. How to use : Caching // uncached selections $('.slide').fadeIn(); $('.slide').css('color','blue'); $('.slide').on('click',function(){     console.log('hello jQuery'); }); // this also supports chaining! var slides = $('.slide'); slides     .fadeIn()     .css('color','blue')     .on('click', function(){         console.log('hello jQuery');     }); How to avoid re-querying the DOM unless absolutely necessary
  • 64. How to use : Attributes // gets the value of an attribute // for the first element in a set only var link = $('a').attr('href'); console.log(link); // www.google.com // sets the value of an attribute $('a').attr('href','www.jquery.com'); // we can also set multiple // attributes at the same time $('a').attr({     title: 'jQuery!',     href: 'http://google.com' }); <a href='www.google.com'> Click me ! </a> <a href='#'> Another link </a> <a href='#'> Just another link </a> Getting and settings DOM attributes of elements
  • 66. How to use : Properties var elem = $('input[type=checkbox]'); console.log(elem.prop('checked')); //true console.log(elem.is(':checked')); //true // change property elem.prop('checked',''); //or elem.removeProp('checked'); <a href='#'> Another link </a> <a href='#'> Just another link </a> <input type='checkbox' checked/> Getting and settings DOM properties of elements
  • 68. How to use : Data var last = $('.slide:last'); // Set some data last.data('description', 'Summarizes content'); // You can then access this data // as follows: console.log(last.data('description')); // Summarizes content Storing and retrieving arbitrary data using specific DOM elements – Can be used to store data in key/value pairs – Data is stored against any DOM elements <ul> <li class='slide'>CSS</li> <li class='slide'>AJAX</li> <li class='slide'>Summary</li> </ul>
  • 69. How to use : Data var last = $('.slide:last'); // Set some data last.data('description', 'Summarizes content'); // You can then access this data // as follows: console.log(last.data('description')); // Summarizes content Storing and retrieving arbitrary data using specific DOM elements – Can be used to store data in key/value pairs – Data is stored against any DOM elements <ul> <li class='slide'>CSS</li> <li class='slide'>AJAX</li> <li class='slide' data-description='Summarizes content'>Summary</li> </ul>
  • 71. How to use : CSS // Gets a CSS property var bgColor = $('.slide').css('backgroundColor'); console.log(bgColor); //gray // Sets a CSS property $('.slide').css('backgroundColor','blue'); // Sets multiple CSS properties $('.slide').css({ 'width':'1600', 'height':'900', 'color':'blue', 'backgroundColor':'gray' }); Methods for getting and setting CSS-related properties of elements
  • 72. How to use : CSS $('.slide:first').addClass('visible'); $('.slide:first').removeClass('pending'); $('.slide').toggleClass('visible'); Supports some other utility methods : <li class="slide pending"> CSS </li> <li class="slide pending"> AJAX </li>
  • 73. How to use : CSS $('.slide:first').addClass('visible'); $('.slide:first').removeClass('pending'); $('.slide').toggleClass('visible'); Supports some other utility methods : <li class="slide pending visible"> CSS </li> <li class="slide pending"> AJAX </li>
  • 74. How to use : CSS $('.slide:first').addClass('visible'); $('.slide:first').removeClass('pending'); $('.slide').toggleClass('visible'); Supports some other utility methods : <li class="slide visible"> CSS </li> <li class="slide pending"> AJAX </li>
  • 75. How to use : CSS $('.slide:first').addClass('visible'); $('.slide:first').removeClass('pending'); $('.slide').toggleClass('visible'); Supports some other utility methods : <li class="slide"> CSS </li> <li class="slide pending visible"> AJAX </li>
  • 77. How to use : Events Registering behaviours which are applied when a user interacts with the browser : // Binding a click event to elements // with the class 'slide' $('.slide').on('click', function(){     $(this).css('color','red');  }); // Remove just the click event handler $('.slide').off('click','**'); // Remove all event handlers from slides $('.slide').off();
  • 78. How to use : Events Other jQuery events methods: - $(elem).load(function(e){ ... }); - $(elem).unload(function(e){ ... }); - $(elem).click(function(e){ ... }); - $(elem).dblclick(function(e){ ... }); - $(elem).hover(function(e){ ... }); - $(elem).blur(function(e){ ... }); - $(elem).focus(function(e){ ... }); - $(elem).change(function(e){ ... }); - $(elem).keydown(function(e){ ... }); - $(elem).keyup(function(e){ ... }); - $(elem).resize(function(e){ ... }); - $(elem).scroll(function(e){ ... }); - $(elem).submit(function(e){ ... });
  • 79. How to use : Ajax Supports both short and long-hand methods for making Ajax requests Cross-browser XHR without the headaches! Performing asynchronous HTTP requests
  • 81. How to use : Ajax // Retrieve the latest version of a web page $.ajax({   url: "slides.html", type: 'GET', // (POST | PUT | DELETE | ..) dataType: 'html', // (xml | json | script | ..) cache: false, data : { from : 1 , to : 5 }, beforeSend: function(xhr){ // Pre-request callback }, // What to do if this is successful: success: function(html) {    $("#results").append(html);   }, // What to do if this fails: error: function() {       //something went wrong } });
  • 82. How to use : Ajax // Get data $.get('slides.html', function(data) {   $('.result').html(data); }); // Post data $.post('slides.php', { name: 'AJAX' },  function(data) {   $('.result').html(data); }); // Get JSON data $.getJSON('slides.json', function(data) {   console.log(data); }); // Load a JavaScript file $.getScript('slides.js', function(data) { console.log(data); });