3. ?jQuery
http://jquery.com-
http://code.msdn.microsoft.com/KB958502/Release/ProjectReleases.aspx?Rel
easeId=1736
To enable Intellisense support, add this to the top of
your .js file:
/// <reference path="~/shared/js/jquery-vsdoc.js"/>
4. JavaScript Library Speed Comparison
Framework Speed Comparison
6000
5000
4000
3000
2000
1000
0
Firefox 3.0.4 Opera 9.62 Google Chrome Safari 3.1.2 Internet Explorer Internet Explorer Internet Explorer Internet Explorer Avg
5.5 6.0 7.0 8.0
MooTools jQuery Prototype YUI Dojo
5. $ == jQuery is simply an “alias”
DOM
window.onload = function() {
…
}; -
X $(document).ready(function(
){
...
HTML-
DOM
});
$ (function( ) {
//when the DOM is ready to be
used
});
6. $(document).ready(function() { :each(callback)
$("div").each(function (i) {
alert(„DivNumber:‟+i+$(this).text());
callback
});
)};
<div>First Div</div>
<div>Second div</ div >
continue(); break();
$(document).ready(function() {
alert(„Number of divs on Page:‟+$("div").length);
)};
<div>First Div</div>
jQuery :length
<div>Second div</ div >
17. :even
$(document).ready(function() {
$("tr:even").css("background-color", "#bbbbff");
)};
<table>
<tr><td>Row 1</td></tr> - :odd
<tr><td>Row 2</td></tr>
</table>
One Two Thre Four One Two Thre Four
$(document).ready(function() { e e
$("tr:odd").css("background-color", "#bbbbff");
)};
One Two Thre Four One Two Thre Four
<table>
<tr><td>Row 1</td></tr>
e e
<tr><td>Row 2</td></tr> One Two Thre Four One Two Thre Four
</table>
e e
One Two Thre Four One Two Thre Four
e e
43. -
$(document).ready(function() {
$("#main").find("#childDivTwo") //now childDivTwo is selected element
now selected elements childDivTwo and
.andSelf()
.css("border","5px solid red") main
:andSelf( )
.end() //add red border to childDivTwo and main
.find("span") div
.css("border","5px solid green") //now childDivTwo is again selected
.end() //now span with content lol is selected
:end( )
.end() add green border to span with content lol
now childDivTwo is selected
.css("border-top","5px solid black");
)}; //now main div is selected
<div id="main"> //change top border color of div main to
Main Div black
<div id="childDivOne">Child one</div>
<div id="childDivTwo">Child Two
<span>lol</span>
</div>
</div>
57. $(“div”).hide(“slow”, function() {
alert(“The DIV is hidden”);
});
$(“div”).show(“fast”, function() {
$(this).html(“Hello jQuery”);
}); // this is a current DOM element
72. $.trim() Trims strings
$.each() Iterates through properties and
collections
$.grep() Filters arrays
$.map() Iterates through array, translating items
into new array
$.inArray() Returns index position of value in array
$.makeArray() Converts array-like object into an array
$.unique() Returns array of unique elements in
original array
$.extend() Extend target object with properties of
other objects
$.getScript() Dynamically load a script from url
74. (function ($) {
jQuery.fn.bolder = function() {
return $(this).each(function() {
this wrap(“<b></b>”);
});
};
Sample div })(jQuery);
Another div
$(document).ready(function(){
$(“div”).bolder();
});
<div>Sample div</div>
<div>Another div</div>
75. jQuery UI
Moved many user interface plug-ins into one
core
Supported by core contributors
Includes (currently in v1.6):
• Coming in 1.7: Layout controls, menus, tooltips, more
• Drag / Drop • Calendar • Auto Complete
• Sortable • Slider • Color Picker
• Selectables • Table • Progress Bar
• Resizables • Tabs • Spinner
• Accordion • Shadow • Magnifier
http://ui.jquery.co
76. Microsoft AJAX Framework
ASP.NET AJAX + jQuery = Microsoft AJAX
Framework
ASP.NET AJAX jQuery
AJAX Requests Selectors
Components
and Controls
Animations
Client Templates
AJAX Control Toolkit Plugins
76
77. Use MS Library for:
AJAX / UpdatePanels
Creating custom classes and controls
Use jQuery for:
DOM manipulation
CSS manipulation
Event binding/handling
UI controls: AJAX Control Toolkit or jQuery UI?
Look to AJAX Control Toolkit first (better integration)
jQuery UI offers better selection (not in code base yet)
77