An introduction to jQuery. How to access elements, what you can then do with them, how to create elements, a bit of AJAX and some JSON. Given as a lecture in the fh ooe in Hagenberg, Austria in December 2011.
6. 5000 x
011
Around 50% of
09.2
the top 10,000
websites use
Top 10k Sites using jQuery
jQuery.
http://blog.builtwith.com/2011/10/31/jquery-version-and-usage-report/
15. // we can call methods on it
$('ul li').hide();
// we can treat it like an array
$('ul li')[0]
// we can iterate over it..
$('ul li').each(function(i, x) {
console.log($(this));
});
22. $('form#login')
// hide all the labels.optional
.find('label.optional').hide().end()
// add a red border to any password
.find('input:password')
.css('border', '1px solid red').end()
// add a submit handler to the form
.submit(function(){
return confirm('Are you sure?');
});
http://simonwillison.net/2007/Aug/15/jquery/
34. J v Sr AJAX
var request = new XMLHttpRequest();
request.open('GET', 'http://www.mozilla.org/', false);
request.send(null);
if (request.status == 200) {
console.log(request.responseText);
}
[...]
35. AJAX w Q r
$('#intro').load('/some/file.html');
43. Wr r w
jQuery.fn.hideLinks = function() {
this.find('a[href]').hide();
return this;
}
$('p').hideLinks();
44. U L
http://jquery.com/
http://docs.jquery.com/
http://docs.jquery.com/Tutorials
http://plugins.jquery.com/
http://jqueryui.com/
45. L I
“Can you read this, Luke Skywalker?“ http://www.flickr.com/photos/49462908@N00/4109940538/
“Few people knew that Fett auditioned for a role in Raiders of the Lost Ark (Explore)” http://www.flickr.com/
photos/27271711@N04/3005974444/
“Pink Storm Cloud” http://www.flickr.com/photos/83346641@N00/3526917649/
“Lost” http://www.flickr.com/photos/st3f4n/4392451969/
“Clone Terror with Jelly Beans” http://www.flickr.com/photos/kalexanderson/5461205156/
“Toy Torture” http://www.flickr.com/photos/st3f4n/4222365229/
“Hard To Tap Dance With Diving Flippers” http://www.flickr.com/photos/47287396@N05/5351991389/
“Baby care lesson by Darth Vader” http://www.flickr.com/photos/49462908@N00/4370515705/
“Introducing the Imperial team for the Winter Olympics” http://www.flickr.com/photos/
49462908@N00/4352088960/
“Everyone’s nightmare” http://www.flickr.com/photos/49462908@N00/4340808219/
“It’s Fun To Stay At The...” http://www.flickr.com/photos/83346641@N00/3578775702/
“Stay active” http://www.flickr.com/photos/99472898@N00/4435490471/