A JavaScript Library
jQuery.com
Seperation of Concerns
Before/After
<a href="#" onclick="alert('hello');"><font color="#ff0000"><strong>Click Me</strong></font></a>
<!-- CSS: Same file or different --> .clicker { color: #FF0000; font-weight: bold; } <!-- JavaScript: Same file or different --> $(document).ready(function(){ $(".clicker").click(function(){ alert('hello'); }); }); <!-- HTML --> <span class=”clicker”>Click Me</span>
"Hell is other Browsers"
Additional Functionality
Seperation of concerns is a web dev principal. We have been using it for years with seperating the concern of content (i.e. HTML) and display (i.e. CSS). It's logical that we do the same with JavaScript, we seperate it from the html. What does that mean? Seperate JavaScript files? Not at all - think the onclick event handler on almost anything in HTML, that is tightly linking the javascript to the element - even if it calls a javascript method in a seperatye file. Seperation means that something externally attaches the javascript to the element at runtime, like CSS does for design.
Browser compatibility is another issue - different browsers have both a different DOM, and JavaScript engine. Compatibility is tough - so jQuery (tries) to hide the differences from developers. It is not perfect, as I found out with KeyPress issues in FireFox (bug #3311 and $(document) vs $(body)), but it is better than starting off yourself.
Additional functionality like the ability to have a foreach loop.
Development | High Profile Usage |
Microsoft
|
Match Amazon NBC MLB Bank of America Technorati Salesforce Monster xerox |
<span>Some text in a paragraph tag</span>
<span>Some more text in another paragraph tag</span> <span id="span1">Last text in a paragraph but has an id</span> |
Selector:
Some things to try:
$(document).ready(function() { $("#demo1input").keyup(function(e) { $($("#demo1input").val()).css("background-color","yellow"); }); }); |
Ajax not AJAX
Crossing the boundaryAJAX is Async JavaScript And XML, while Ajax is the modern thinking where the X isn't XML - it could be something like JSON.
Going across domain boundaries is a tough problem - how do i get results outside of my domain? From 1.2+ jQuery allows you to go over domain boundaries because of a cool callback system.
JSON Data: json.txt View Code $(document).ready(function() { $("#demo2Button").click(function(e) { $.getJSON("json.txt", function(data) { var message = "Welcome :" + data.firstName; $.each(data.website, function(i, value) { message += "\n<br/>Website " + i + ": " + value; }); $("#demo2SampleArea").append(message); }); }); }); |
15 Effects - show, hide, slide in, slide out etc...
Toggling with one function
Callbacks
jQuery object and function level support.
View jQuery Object Plugin Code
jQuery.fn.debug = function() { return this.each(function(){ alert(this); }); };
View jQuery Object Plugin Usage
$(":submit").debug();
UI is a optional plugin
jQueryUI.comDate Picker:
View Code
$(document).ready(function() { $("#demo3Tabs").tabs(); $("#demo3ProgressBar").progressbar(); $("#demo3Slider").slider({ change: function(event, ui) { $('#demo3ProgressBar').progressbar('option', 'value', $('#demo3Slider').slider('option', 'value')); } }); $("#demo3DatePicker").datepicker(); });
Puff Out/ Puff In Fold Out/ Fold In Pulsate View Code$(document).ready(function() { $("#demo4PuffOut").click(function() { $("#chastingStarsImage").hide("puff"); }); $("#demo4PuffIn").click(function() { $("#chastingStarsImage").show("puff"); }); $("#demo4FoldOut").click(function() { $("#chastingStarsImage").hide("fold"); }); $("#demo4FoldIn").click(function() { $("#chastingStarsImage").show("fold"); }); $("#demo4Pulsate").click(function() { $("#chastingStarsImage").effect("pulsate", { times: 3 }, 1000); }); }); |
You can drag me around
I am a drop target.
I'll say something interesting if you drop on me View Code $(document).ready(function() { $("#demo5Draggable").draggable(); $("#demo5Droppable").droppable({ drop: function(event, ui) { $("#demo5Droppable").html("<strong>I lied - nothing interesting</strong>"); } }); }); |
View Code $(document).ready(function() { $("#demo6Selectable").selectable(); }); |
Thanks to http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
Entire presentation built in HTML & jQuery
Everything (exluding images) ~100k
Less than 100 lines of JavaScript for all slide show functionality