Beruflich Dokumente
Kultur Dokumente
Sathish Chandra
Sanga
24/09/2012
Setting Expectations
About Me
JavaScript Vs jQuery
Dom Navigations
Browser Differences
Tedious
Time Consuming
Error Prone
Browser DOM really sucks, and
this is where jQuery comes to
rescue.
Quality of Life !
A Quality of Life by
jQuery
Just Hiding divs with JavaScript
divs= document.getElementByTagName(div);
for(i=0; i<divs.length; i++){
divs[i].style.display = none;
}
?What is jQuery
What is jQuery?
jQuery is JavaScript framework.
Its a Open source JS Library.
It's a light-weight library (31KB,
Minified and Gzipped, v1.7)
Easy and fast HTML DOM Selection
Cross browser compatible
Advantages of jQuery
Well documented
Simplifies Interaction b/w HTML & JS.
Developer community & Online
presence
Extensible
CSS like Syntax
Works with other libraries
ExtJS, Scriptaculous ,Prototype , Mootools
Tons of Plugins
Very compact and fluent programming model
Google
Microsoft
Twitter
Mozilla
Apple
flipKart
ASK
IBM
Amazon
Digg
Wordpress
eBay
ESPN
jQuerys History
jQuery was first released in 2006
Created by John Resig from Mozilla.
Getting Started
Import JQuery
Download the latest version from http://jquery.com
<html>
<head>
<script type="text/javascript" src="jquery1.7.min.js" />
Magic - $()
Since the jQuery() function is called so
often, the $ variable is set up as an alias to
jQuery
If youre also using another library, you can
revert to the previous $ function with
jQuery.noConflict();
Create , Manipulate, Selects
elements
HTML&DOM
jQuery Mantra
Every operation boils down to:
Find some HTML stuff
Do something to it
Find
Do
$
(div).addClass(whiteBorder
)
GET >> ACT
Chainability
Setting up jQuery
(function($) {
$(function() {
});
})(jQuery);
// Full Syntax
$(document).ready(function(){
});
jQuery Selectors
Selectors
Basic Selectors:
By ID
$(#div1)
By Class
$(.classA)
By Tag
$(div)
<div id=div1
class=classA>XYZ</div>
Combination &
Hierarchy
// find by id + by class
$(#content, .menu)
// multiple combination
$(h1, h2, h3, div.content)
$(table td)
// descendants
$(tr > td)
// children
$(label + input)
// next
$(#content ~ div) // siblings
$(input:checkbox)// checkboxes
$(input:radio) // radio buttons
$(:button)
// buttons
$(:text) // text inputs
$(input:checked)
$(input:selected)
$(input:enabled)
$(input:disabled)
//
//
//
//
checked
selected
enabled
disabled
SELECTORS DEMO
Selector pitfalls
Don'ts Dos
$(div#myId)
$(#myId)
$(.myclass #myId)
$(#myId)
$(.myclass)
$(#nearestId
.myClass)
$(#parentId #myId)
$(#myId)
$(span .myclass)
$(.myClass) $
(#myID)
and many more
Attributes
.atttr()
.addClass()
.hasClass()
.removeAttr()
.html()
.val()
and many more
( http://api.jquery.com/category/attributes/ )
Attributes
Get
.attr(id)
.attr(id, myId)
.html()
.html(<p>Hi</p>
.val()
.css(color)
.width()
Set
.val(100)
.color(red)
.width(100)
Traversing
.parent()
.children()
.siblings()
.next()
.find()
.closest()
and many more
(http://api.jquery.com/category/traversing/ )
Manipulation
.append()
.appendTo()
.prepend()
.prependTo()
.remove()
.empty()
and many more
(http://api.jquery.com/category/manipulation/ )
jQuery Events
Events
When the DOM is ready
$(document).ready(function(){
//
});
Fires when the document is ready for
programming.
Uses advanced listeners for detecting.
Events
Possible event values:
blur, focus, load, resize, scroll, unload,
beforeunload, click, dblclick, mousedown,
mouseup, mousemove, mouseover, mouseout,
mouseenter, mouseleave, change, select,
submit, keydown, keypress, keyup, error
// attach / trigger
elem.click(fn) / elem.click()
Events
$(div).trigger(click);
Live Events
// attach live event
(div).live(click, fn);
// detach live event
(div).die(click, fn);
EVENTS DEMO
Effects
Effects
.hide()
.show()
.slideUp()
.slideDown()
.toggle()
.fadeIn()
.fadeOut()
.animate()
and more (http://api.jquery.com/category/effects/ )
Effects
// just show $(div).show();
// slow=600ms $(div).show(slow);
// hide fast, fast=200ms $(div).hide(fast);
// hide or show in 100ms $(div).toggle(100);
$(div).slideUp();
$(div).slideDown(fast);
$(div).slideToggle(1000);
$(div).fadeIn(fast);
$(div).fadeOut(normal);
$(div).fadeTo (fast, 0.5);
Animation Effects
// .animate(options, duration)
$(div).animate({
width: 90%,
opacity: 0.5,
borderWidth: 5px
}, 1000);
// chaining animation
$(div).animate({width: 90%},100)
.animate({opacity: 0.5},200)
.animate({borderWidth: 5px});
Animation Styles
backgroundPosition
borderWidth
borderBottomWidth
borderLeftWidth
borderRightWidth
borderTopWidth
borderSpacing
margin
marginBottom
marginLeft
marginRight
marginTop
outlineWidth
padding
paddingBottom
paddingLeft
paddingRight
paddingTop
height
width
maxHeight
maxWidth
minHeight
minWidth
font
fontSize
bottom
left
right
top
letterSpacing
wordSpacing
lineHeight
textIndent
EFFECTS DEMO
AJAX
Source: w3schools.com
AJAX
.ajax()
.load()
.get()
.post()
.getJSON()
.getScript()
and many more
(http://api.jquery.com/category/ajax/ )
AJAX Loading
Content
$(div).load(content.htm);
// passing parameters
$(#content).load(getcontent.jsp,
{id:33,
type:main});
- $.ajax({url:"test1.txt",
success:function(result){
$("div").html(result);
}});
Ajax Params
$.ajax, $.ajaxSetup
beforeSend
contentType
data
dataType
error
processData
success
timeout
type
url
AJAX DEMO
jQueryUI Plug-in
To build highly interactive web applications.
. Date Picker
. Tabs
. Accordion
. Progress Bar
. Slider
. Dialog
. Drag & Drop
and many more(http://http://jqueryui.com)
jQueryUI Sample
Codes
Date Picker
$( "#textBoxId" ).datepicker();
http://jqueryui.com/demos/datepicker/
Progress Bar
$( "#progress" ).progressbar({ value:
37 });
http://jqueryui.com/demos/progressbar/
Tabs
$( "#tabs" ).tabs();
http://jqueryui.com/demos/tabs/
dataTable Plug-in
.
.
.
.
dataTable
incorporation
. I already had a table
- $(document).ready(function() {
('#myTable').dataTable(); //default Options
} );
- $(document).ready(function() {
$('#myTable').dataTable({
"bPagination": false }); //no Pagination
} );
dataTable
incorporation
-
$(document).ready(function() { $
('#myTable').dataTable({
"bPagination": false,
"aoColumns": [
{"sType": "num-html"},//Number Column
{"sType": "date"},//date Column
{"bSortable": false} ]//no Sorting
});
} );
dataTable Params
Whole Table
bAutoWidth
bFilter
bPaginate
bLengthChange
bSort
bStateSave
sScrollX
aoColumns
bSearchable
bSortable
bVisible
sType
sWidth
Good to Check
jQuery Forum ( http://forum.jquery.com/)
Documentation ( http://docs.jquery.com/ )
dataTable Plugin (http://www.datatables.net/ )
Auto-Complete
(http://archive.plugins.jquery.com/project/jam
es )
jQuery UI (http://jqueryui.com/ )
Plugins (http://plugins.jquery.com/ )
For Practice(www.w3schools.com )
Thank you