Manual Jquery
Manual Jquery
JavaScript
A script language that interpreted
by browser
OOP
Dynamic typing
Run-time evaluation
JavaScript Libraries
jQuery
Mootools
Prototype
YUI
Introduction to jQuery
Introduction to jQuery
Why do I want it
Rich Internet Applications (RIA)
Dynamic HTML (DHTML)
How do I get it
www.jquery.com
Summary
Introduction, installation, Howdy World,
Introduction to jQuery
Installation
just JavaScript
The DOM
Document Object Model
jQuery is DOM scripting
Heirarchal structure of a web page
You can add and subtract DOM elements on
the fly
You can change the properties and contents
of DOM elements on the fly
The DOM
a cross-platform and language-independent convention for representing
and interacting with objects in HTML, XHTML and XML documents.
Aspects of the DOM (such as its "Elements") may be addressed and
manipulated within the syntax of the programming language in use.
Wikipedia
jquery(document).ready(function(){};);
jquery().ready(function(){};)
jquery(function(){};)
jquery(dofunc);
$(dofunc);
Selecting Elements
Creating a wrapped set
$(selector)
selector:
$(#id)
id of element
$(p)
tag name
$(.class)
CSS class
$(p.class) <p> elements having the CSS class
$(p:first) $(p:last) $(p:odd) $(p:even)
$(p:eq(2))
gets the 2nd <p> element (1 based)
$(p)[1]
gets the 2nd <p> element (0 based)
$(p:nth-child(3))
gets the 3rd <p> element of the parent. n=even, odd too.
$(p:nth-child(5n+1)) gets the 1st element after every 5th one
$(p a)
<a> elements, descended from a <p>
$(p>a)
<a> elements, direct child of a <p>
$(p+a)
<a> elements, directly following a <p>
$(p, a)
<p> and <a> elements
$(li:has(ul))
<li> elements that have at least one <ul> descendent
$(:not(p))
all elements but <p> elements
$(p:hidden)
only <p> elements that are hidden
$(p:empty) <p> elements that have no child elements
Formatting Elements
.css(property, value)
.html()
.val()
(form elements)
.text()
.addClass(class)
.removeClass(class)
Adding Events
Mouseover events bind, hover, toggle
Button click events
Keystrokes
Event Background
DOM Level 2 Event Model
$(img).bind(click,function(event){alert(Howdy;});
$(img).bind(click,imgclick(event));
Allows unbinding the function
$(img).unbind(click,imgclick());
$(img).unbind(click);
$(img).one(click,imgclick(event));
Only works once
$(img).click(imgclick);
$(img).toggle(click1, click2);
$(img).hover(mouseover, mouseout);
jQuery Core
jQuery(selector, [ context ]): Accepts a
jQuery(element)
jQuery(elementArray)
jQuery(jQuery object)
jQuery()
jQuery Events
js
function printhello(){
$(#hello).html(Hello,
jQuery!);
}
$(document).ready(printhello());
Same as window.onload???
js
$(document).ready(function(){
$(#hello).html(Hello, jQuery!);
});
jQuery Events
.bind()
.blur()
.change()
.click()
.focus()
.hover()
.select()
.toggle()
.trigger()
.submit()
.mousedown()
.mouseenter()
.mouseleave()
.keypress()
.keyup()