Jonathan Sharp is a freelance developer and member of the jQuery team. He gave an introduction to jQuery covering the following key points:
1. jQuery is a JavaScript library that simplifies DOM manipulation, event handling, animations and Ajax interactions. It uses CSS selectors to find elements and chaining to perform multiple operations in one line of code.
2. The core concepts of jQuery include finding elements and performing actions on them, creating new elements and appending them, chaining and implicit iteration, and understanding the different parameter types like selectors, HTML and DOM elements.
3. An overview of the jQuery API was provided covering core functionality, selectors, attributes, traversing, manipulation, CSS, events
6. Who uses jQuery
• 35% of all sites that use JavaScript, use jQuery
• 1 out 5, of all sites, use jQuery
reddit.com whitehouse.gov overstock.com
espn.com wikipedia.org )me.com
ibm.com microsob.com capitalone.com
stackoverflow.com amazon.com usatoday.com
kickball.com netflix.com ning.com
boxee.tv bing.com wordpress.com
bit.ly monster.com dell.com
twitpic.com tv.com twi]er.com
h]p://trends.builtwith.com/javascript/JQuery
7. Who uses jQuery
• 35% of all sites that use JavaScript, use jQuery
• 1 out 5, of all sites, use jQuery
reddit.com whitehouse.gov overstock.com
espn.com wikipedia.org )me.com
ibm.com microsob.com capitalone.com
stackoverflow.com amazon.com usatoday.com
kickball.com netflix.com ning.com
boxee.tv bing.com wordpress.com
bit.ly monster.com dell.com
twitpic.com tv.com twi]er.com
h]p://trends.builtwith.com/javascript/JQuery
10. Add class ‘odd’ to a table row...
var tables = document.getElementsByTagName(‘table’);
for (var t = 0; t < tables.length; t++) {
var rows = tables[t].getElementsByTagName("tr");
for (var i = 1; i < rows.length; i += 2) {
if (!/(^|s)odd(s|$)/.test(rows[i].className)) {
rows[i].className += ‘odd’;
}
}
};
...becomes...
h]p://jsbin.com/esewu/edit
13. Using jQuery we can do this
jQuery(‘table tr:nth-child(odd)’).addClass(‘odd’);
jQuery Selector (CSS Expression)
jQuery func)on
14. Using jQuery we can do this
jQuery(‘table tr:nth-child(odd)’).addClass(‘odd’);
jQuery Selector (CSS Expression)
jQuery func)on
jQuery Collec)on
15. Using jQuery we can do this
jQuery(‘table tr:nth-child(odd)’).addClass(‘odd’);
jQuery Selector (CSS Expression)
jQuery func)on
jQuery Collec)on jQuery Method
18. Further Reduced
var jQuery = function(...) { ... };
// $ is a valid variable character in JavaScript
var $ = jQuery;
$(‘table tr:nth-child(odd)’).addClass(‘odd’);
79. Overview of jQuery API
• Core $.each(data.items, function(i,item){
• Selectors $("<img/>")
.attr("src”,item.media.m).appendTo("body");
• A]ributes if ( i == 30 ) return false;
});
• Traversing
• Manipula)on
• CSS
• Events
• Effects
• Ajax
• U)li)es
80. What happen to the $ alias and the $
(document).ready() event
<!DOCTYPE html> <html>
<head>
<script src=“jquery.js”></script>
<script>
$(document).ready(function{
//jQuery code here
})
</script>
</head>
<body>
</script>
</body>
</html>
81. What happen to the $ alias and the $
(document).ready() event
<!DOCTYPE html> <html>
<head>
<script src=“jquery.js”></script>
<script>
$(document).ready(function{
alert($(document).jquery);
})
</script>
</head>
<body>
</script>
</body>
</html>
82. What happen to the $ alias and the $
(document).ready() event
<!DOCTYPE html> <html>
<head>
<script src=“jquery.js”></script>
<script>
$(document).ready(function{
alert($(document).jquery);
})
</script>
</head>
<body>
</script>
</body>
</html>
83. What happen to the $ alias and the $
(document).ready() event
<!DOCTYPE html>
<html>
<body>
<script src=“jquery.js”></script>
<script>
alert($(document).jquery);
</script>
</body>
</html>
84. What happen to the $ alias and the $
(document).ready() event
<!DOCTYPE html>
<html>
<body>
<script src=“jquery.js”></script>
<script>
alert($(document).jquery);
(function($){
alert($().jquery);
})(jQuery);
</script>
</body>
</html>
102. jQuery News
• jQuery.org & Founda)on (Sobware Freedom Law
Center)
• Tax‐deduc)ble dona)ons
• Four conferences next year (Boston, San Francisco,
London, and online)
• Infrastructure Upgrade (MediaTemple Sponsorship)
• New Plugin site (h]p://plugins.jquery.com)
• jQuery Forum (moving away from Google Groups)