SlideShare une entreprise Scribd logo
1  sur  35
2009 Mats Bryntse
Contents
 What is JavaScript
 JavaScript Basics
 Functions
 Objects
 Bad parts
 Prototype
 Scope
 Ajax
 JSON
 Debugging
 Tools
 Performance
 Events
 Error handling
 Future of JavaScript
What is JavaScript
- The worlds most popular programming language..?

JavaScript
ECMAScript

DOM

BOM

 ECMAScript

 Current version in browsers is ECMA-262 edition 3, 3.1 to be finalized in December 2009
 http://www.ecma-international.org
 Not tied to web browsers

 DOM – Document object model



API for working with XML/HTML, 3 levels (level 1 became W3C recommendation in October 1998)
http://www.w3.org/DOM/

 BOM (Browser object model)

 navigator, location, screen, XMLHttpRequest, ActiveXObject...
 No backing standard
JavaScript overview
 JavaScript is a class-free, object-oriented language
 Dynamic language, you can change any object at any time
 Prototypal inheritance (inherit from objects)
 Lamda functions (or ’anonymous’ functions)
 5 primitive types:






number
string
boolean
null
undefined

 Loosely typed language

var a = 2;
a === "2" // false
a = "2"; // a is now a string
a === "2" // true
Functions
Functions are first class objects

var Cat = function () {
// This is called a constructor function
this.purr = function() {};
}

Create instance: use the new keyword
var myCat = new Cat();
typeof(myCat) // ”object”, not very intuitive
myCat instanceof Cat // true, instanceof gives the expected answer
// Watch out when forgetting the new operator
var cat = Cat();
window.purr // window object is now clobbered

Function arguments available through arguments
function myFunc() {
return arguments.length;
}
myFunc(”a”, ”b”, ”c”); // returns 3
Objects and arrays
 Everything that is not a primitive derives from Object
window.toString instanceof Object // = true

 Objects are associative arrays / hashtables
var a = { text : 'test'};
a["text"] == a.text // true

 Testing for object property
”text” in a // true

 Enumerating object properties

for (var o in window) {
console.log(o + ':' + window[o]);
}

 Array basics








push : adds an element
length
concat : join 2 arrays
join(string) : string represenation of the array split by the argument
slice(start, end) : returns elements between args
sort ([function]) : sorts by alphabet or by function supplied as arg
pop : extracts last element
Some bad parts
Global variables

 window object is shared by everyone
 no warning or crash if a variable is overwritten
 Easy to end-up with ”function soup”, an unmaintainable mess of

global objects & functions (MS Virtual Earth)

eval & with

var o = {};
with (o) {
prop = 2; // prop isn’t defined on object o and ends up on the global object
}
alert(prop); // 2

== & !=
typeof
semi-colon insertion
0.1 + 0.2 == 0.3 // false (IEEE 754 floating point)
Prototype
Every function has a prototype, a shared object
var sword = function() {
this.swing = function(){
console.log(”Swing”);
};
};

// Every sword instance will have its own version of swing

var sword = function() {
};
sword.prototype.swing = function(){ // Every sword created will share this function
console.log(”Swing”);
};

Use hasOwnProperty to distinguish prototype methods

from own properties
Execution Scope
Scope is the execution context, the this property
var obj = {
number : 42,
showNumber: function () {
alert(this.number);
}
};
obj.showNumber(); // 42

document.body.onclick = obj.showNumber; // clicking the body shows ”undefined”

call and apply can bind a new scope to a function
var anotherObj = { number : ”blablabla” };
obj.showNumber.call(anotherObj); // ”blablabla”

 call (scope, arg1, arg2, ...)

apply(scope, [arg1, arg2, ...])

Variable scope: function scope, not block scope
for(var i = 0; i<5;i++) {}
alert(i); // 5
Asynchronous JavaScript and XML
Term coined by Jesse James Garret in 2005
XHR added in IE5 through an ActiveX object
All browsers (IE7+) supports the

XMLHttpRequest object
Cross domain restrictions apply
IE8 implements XDomainRequests, (does not
send cookies)
JSON
 JavaScript Object Notation
 Invented by Douglas Crockford of Yahoo
 The preferred data transfer format of the web
 More lightweight than XML
 { ”property” : ”value”}
 Possible value types:








String
Number
Object
Array
true
false
null

 eval the JSON to get a native JS object, or use a JSON parser.

ECMAScript 3.1 will have native support for JSON.parse and
JSON.stringify (already in FF3.1)
Debugging
FireBug for Firefox(Lite for IE) (1.4 adds JSON viewer)
Fiddler (if using http://localhost, use http://localhost.)



JsonViewer plugin
SyntaxViewer plugin

IE: Internet Options -> Advanced ->

Disable script debugging
debugger; attaches a client-side debugger
IE8 has a developer toolbar builtin, for previous versions
there is IE Developer Toolbar
Tools
 Validators
 JsLint
 JavaScriptLint

 Minifiers
 JsMin
 Dojo ShrinkSafe
 YUI Compressor

 Unit testing
 JsUnit
 YUI Test
 Dojo Object Harness

 Documentation generators
 JsDoc
 YUI Doc

 Secure execution environments
 ADSafe (Crockford)
 Caja
Performance
 YUI Exceptional Performance Team
 Use Yslow plugin to FB
 If using namespaced objects repeatedly, assign to a local variable first
BAD
myNS.subNS.obj.prop = 2;
myNS.subNS.obj.name = ”Test”;
myNS.subNS.obj.index = 2345;
BETTER
var m = myNS.subNS.obj;
m.prop = 2;
m.name ....

 Even if the JavaScript engines ran at infinite speed, web pages would not run noticeably

faster. The DOM operations are typically the culprit when it comes to poor
performance.
 Read Steve Souders blog on High performance websites
Events
Events handling in the DOM is tricky, browser

implementations vary.
Using a JS library that normalizes the event object is
very helpful
Registering events the old fashioned way (DOM level
0)
 <a href="http://www.facebook.com” onclick="return fbs_click(this)">Facebook</a>
 element.onclick = function() {}
 Only one listener can be registered, last listener assigned wins

”Correct” way of doing this
 W3C : element.addEventListener(’click’, fn, [executeInCapturePhase])
 IE : element.attachEvent('onclick', fn) // flawed (this points to window in fn,

useless)
Introduce jQuery
jQuery
•
•
•
•

Cross-browser javascript library
Free & Opensource
First released Jan 06 @Barcamp by John Resig
Last stable version 1.10.2
Why jQuery ?
•
•
•
•
•
•

Cross-browser compatibility
Fast & Small
Plug-in
Learning curve & Documentation
Intellisense in VS2008-2010
Microsoft [Ajax Lib & MVC]
Why jQuery ?
Who’s using jQuery
•
•
•
•
•
•
•

Microsoft
Google
Mozilla
Digg
Wordpress & Drupal
HP - IBM - Intel.
Ruby on Rails
Getting Start
• Download jQuery at jquery.com
– <script type="text/javascript" src="/js/jQuery.
js"></script>

• Microsoft CDN or Google CDN
– <script src="http://ajax.microsoft.com/ajax/jquery/jquery1.4.2.js" type="text/javascript"></script>
– <script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jq
uery.js"></script>
Hello world jQuery
• Document ready
$(document).ready(function () {
alert("Hello world jQuery");
});
// Short cut
$(function () {
alert("Hello world jQuery");
});
jQuery Philosophy

Find
someone
from HTML
(selector)

Do
something
to it
(method)
Find some element
Selector
• CSS Style
– $(“#myID”)
// by id
– $(“.myClass”)
// by class name
– $(“myTag”)
// by tag (element name)
– $(“#id, .class, tag”) // multiple
Selector [Hierarchy]
• $("form input")
// descendant
• $("#main > *")// child
• $("#prev ~ div")
// sibling
Selector [Hierarchy]
• $("form input")

// descendant

<form>
<div>
Form is surrounded by the green
outline</div>
<label>
Child:</label>
<input name="name" />
<fieldset>
<label>
Grandchild:</label>
<input name="newsletter" />
</fieldset>
</form>
Selector [Attribute]
•
•
•
•
•
•
•

$("div[id]").
$("input[name='bank']“)
$("input[name^='news']")
$("input[name$='letter']")
$("input[name$='letter']")
$("input[name*='man']")
$("input[id][name$='man']")

//has
//not has
//equal
//begin with
//end with
//contain
Selector [Form]
•
•
•
•
•
•

$("div :text")
$("form :radio")
$("#dvMainForm :checkbox")
$(":button")
$("input:disabled")
$("input:checked")
Do something with them
Attribute
•
•
•
•

$("em").attr("title")
$("label").html()
Get
$("p:first").text()
$("input").val()
• $("em").attr("title", "zupzip")
• $("label").html("zupzip")
Set
• $("p:first").text("zupzip")
• $("input").val("zupzip")
Event
• Bind
– $(“input”).bind(“blur”, fn);

• Trigger
– $(“input”).trigger(“focus”);

• Event Helper
– $(“input”).click(function() { alert(‘click’); });
– S(“input”).click();

• Live
– $(“input”).live(“click”, fn);
Traversing
•
•
•
•

find $("p").find("span").css('color','red');
children $("div").children(".selected").css("color);
parent $("tr").parent().get(0).tagName;
next $("button[disabled]").next().text("this
button is disabled");
• prev $("p").prev(".selected").css("background",
"yellow");
• sibling $(".hilite").siblings() .css("color", "red")
Manipulation
• append $
("p").append("<strong>Hello</strong>");
• appendTo $("span").appendTo("#foo");
• prepend &prependTo
• after $("p").after("<b>Hello</b>");
• before $("p").before("<b>Hello</b>");
Effect
•
•
•
•
•

show / hide
toggle
slide
fade
Custom animation

Contenu connexe

Tendances

Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second LanguageRob Dunn
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIsDmitry Buzdin
 
A Practitioner’s guide to Hardened JavaScript
A Practitioner’s guide to Hardened JavaScriptA Practitioner’s guide to Hardened JavaScript
A Practitioner’s guide to Hardened JavaScriptTom Van Cutsem
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Jaroslaw Palka
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingCodemotion
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin Vasil Remeniuk
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in KotlinLuca Guadagnini
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Stacy Devino
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized军 沈
 
Mobile Open Day: React Native: Crossplatform fast dive
Mobile Open Day: React Native: Crossplatform fast diveMobile Open Day: React Native: Crossplatform fast dive
Mobile Open Day: React Native: Crossplatform fast diveepamspb
 

Tendances (20)

Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
 
A Practitioner’s guide to Hardened JavaScript
A Practitioner’s guide to Hardened JavaScriptA Practitioner’s guide to Hardened JavaScript
A Practitioner’s guide to Hardened JavaScript
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014Patterns for JVM languages - Geecon 2014
Patterns for JVM languages - Geecon 2014
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
Prototype
PrototypePrototype
Prototype
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Mobile Open Day: React Native: Crossplatform fast dive
Mobile Open Day: React Native: Crossplatform fast diveMobile Open Day: React Native: Crossplatform fast dive
Mobile Open Day: React Native: Crossplatform fast dive
 

En vedette

HTML, CSS, JS & Jquery Introduction
HTML, CSS, JS & Jquery IntroductionHTML, CSS, JS & Jquery Introduction
HTML, CSS, JS & Jquery IntroductionIslam AlZatary
 
20121228 jqueryui - button - By Nat
20121228 jqueryui - button - By Nat20121228 jqueryui - button - By Nat
20121228 jqueryui - button - By NatLearningTech
 
Cartegraph Live HTML, CSS, JavaScript and jQuery Training
Cartegraph Live HTML, CSS, JavaScript and jQuery TrainingCartegraph Live HTML, CSS, JavaScript and jQuery Training
Cartegraph Live HTML, CSS, JavaScript and jQuery TrainingShane Church
 
Javascript jQuery jQuery Ui
Javascript jQuery jQuery UiJavascript jQuery jQuery Ui
Javascript jQuery jQuery UiTom Friedhof
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
HTML CSS and Web Development
HTML CSS and Web DevelopmentHTML CSS and Web Development
HTML CSS and Web DevelopmentRahul Mishra
 
HTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery TrainingHTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery Trainingubshreenath
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
Surveying for Widening of the Road Segment 28 Kilo to Kathmandu University
Surveying  for Widening of the Road Segment 28 Kilo to Kathmandu UniversitySurveying  for Widening of the Road Segment 28 Kilo to Kathmandu University
Surveying for Widening of the Road Segment 28 Kilo to Kathmandu UniversityUpendra Oli
 
JavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationJavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationSiarhei Barysiuk
 
Mapserver vs. geoserver
Mapserver vs. geoserverMapserver vs. geoserver
Mapserver vs. geoserver鸣 饶
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsCommand Prompt., Inc
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 

En vedette (20)

HTML, CSS, JS & Jquery Introduction
HTML, CSS, JS & Jquery IntroductionHTML, CSS, JS & Jquery Introduction
HTML, CSS, JS & Jquery Introduction
 
20121228 jqueryui - button - By Nat
20121228 jqueryui - button - By Nat20121228 jqueryui - button - By Nat
20121228 jqueryui - button - By Nat
 
jQueryUI
 jQueryUI jQueryUI
jQueryUI
 
Cartegraph Live HTML, CSS, JavaScript and jQuery Training
Cartegraph Live HTML, CSS, JavaScript and jQuery TrainingCartegraph Live HTML, CSS, JavaScript and jQuery Training
Cartegraph Live HTML, CSS, JavaScript and jQuery Training
 
Javascript jQuery jQuery Ui
Javascript jQuery jQuery UiJavascript jQuery jQuery Ui
Javascript jQuery jQuery Ui
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
PHP HTML CSS Notes
PHP HTML CSS  NotesPHP HTML CSS  Notes
PHP HTML CSS Notes
 
HTML CSS and Web Development
HTML CSS and Web DevelopmentHTML CSS and Web Development
HTML CSS and Web Development
 
HTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery TrainingHTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery Training
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
Surveying for Widening of the Road Segment 28 Kilo to Kathmandu University
Surveying  for Widening of the Road Segment 28 Kilo to Kathmandu UniversitySurveying  for Widening of the Road Segment 28 Kilo to Kathmandu University
Surveying for Widening of the Road Segment 28 Kilo to Kathmandu University
 
JavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationJavaScript Basics And DOM Manipulation
JavaScript Basics And DOM Manipulation
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Mapserver vs. geoserver
Mapserver vs. geoserverMapserver vs. geoserver
Mapserver vs. geoserver
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 

Similaire à jQuery with javascript training by Technnovation Labs

Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Libraryrsnarayanan
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksThomas Fuchs
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)Piyush Katariya
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat Roque
 
Beyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsBeyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsMarcos Caceres
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express jsAhmed Assaf
 
03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuerycrgwbr
 
The current state of web
The current state of webThe current state of web
The current state of webRitesh Kumar
 

Similaire à jQuery with javascript training by Technnovation Labs (20)

JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
oojs
oojsoojs
oojs
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
J Query
J QueryJ Query
J Query
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-Frameworks
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
JS basics
JS basicsJS basics
JS basics
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Beyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsBeyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 Apps
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
 
The current state of web
The current state of webThe current state of web
The current state of web
 

Plus de Prasad Shende

Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Prasad Shende
 
Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Prasad Shende
 
Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Prasad Shende
 
On Job Training Program
On Job Training ProgramOn Job Training Program
On Job Training ProgramPrasad Shende
 
Front-end Development Training by Technnovation Labs
Front-end Development Training by Technnovation LabsFront-end Development Training by Technnovation Labs
Front-end Development Training by Technnovation LabsPrasad Shende
 
Web Design Training in Pune by Technnovation Labs
Web Design Training in Pune by Technnovation LabsWeb Design Training in Pune by Technnovation Labs
Web Design Training in Pune by Technnovation LabsPrasad Shende
 
HTML5 Training in Pune by Technnovation Labs
HTML5 Training in Pune by Technnovation LabsHTML5 Training in Pune by Technnovation Labs
HTML5 Training in Pune by Technnovation LabsPrasad Shende
 
Wordpress Training in Pune by Technnovation Labs
Wordpress Training in Pune by Technnovation LabsWordpress Training in Pune by Technnovation Labs
Wordpress Training in Pune by Technnovation LabsPrasad Shende
 
Drupal Training by Technnovation Labs
Drupal Training by Technnovation LabsDrupal Training by Technnovation Labs
Drupal Training by Technnovation LabsPrasad Shende
 

Plus de Prasad Shende (10)

Domain strength
Domain strengthDomain strength
Domain strength
 
Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]
 
Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]
 
Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]Internship mca mcs mcm 6 1-15 [autosaved]
Internship mca mcs mcm 6 1-15 [autosaved]
 
On Job Training Program
On Job Training ProgramOn Job Training Program
On Job Training Program
 
Front-end Development Training by Technnovation Labs
Front-end Development Training by Technnovation LabsFront-end Development Training by Technnovation Labs
Front-end Development Training by Technnovation Labs
 
Web Design Training in Pune by Technnovation Labs
Web Design Training in Pune by Technnovation LabsWeb Design Training in Pune by Technnovation Labs
Web Design Training in Pune by Technnovation Labs
 
HTML5 Training in Pune by Technnovation Labs
HTML5 Training in Pune by Technnovation LabsHTML5 Training in Pune by Technnovation Labs
HTML5 Training in Pune by Technnovation Labs
 
Wordpress Training in Pune by Technnovation Labs
Wordpress Training in Pune by Technnovation LabsWordpress Training in Pune by Technnovation Labs
Wordpress Training in Pune by Technnovation Labs
 
Drupal Training by Technnovation Labs
Drupal Training by Technnovation LabsDrupal Training by Technnovation Labs
Drupal Training by Technnovation Labs
 

Dernier

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

jQuery with javascript training by Technnovation Labs

  • 2. Contents  What is JavaScript  JavaScript Basics  Functions  Objects  Bad parts  Prototype  Scope  Ajax  JSON  Debugging  Tools  Performance  Events  Error handling  Future of JavaScript
  • 3. What is JavaScript - The worlds most popular programming language..? JavaScript ECMAScript DOM BOM  ECMAScript  Current version in browsers is ECMA-262 edition 3, 3.1 to be finalized in December 2009  http://www.ecma-international.org  Not tied to web browsers  DOM – Document object model   API for working with XML/HTML, 3 levels (level 1 became W3C recommendation in October 1998) http://www.w3.org/DOM/  BOM (Browser object model)  navigator, location, screen, XMLHttpRequest, ActiveXObject...  No backing standard
  • 4. JavaScript overview  JavaScript is a class-free, object-oriented language  Dynamic language, you can change any object at any time  Prototypal inheritance (inherit from objects)  Lamda functions (or ’anonymous’ functions)  5 primitive types:      number string boolean null undefined  Loosely typed language var a = 2; a === "2" // false a = "2"; // a is now a string a === "2" // true
  • 5. Functions Functions are first class objects var Cat = function () { // This is called a constructor function this.purr = function() {}; } Create instance: use the new keyword var myCat = new Cat(); typeof(myCat) // ”object”, not very intuitive myCat instanceof Cat // true, instanceof gives the expected answer // Watch out when forgetting the new operator var cat = Cat(); window.purr // window object is now clobbered Function arguments available through arguments function myFunc() { return arguments.length; } myFunc(”a”, ”b”, ”c”); // returns 3
  • 6. Objects and arrays  Everything that is not a primitive derives from Object window.toString instanceof Object // = true  Objects are associative arrays / hashtables var a = { text : 'test'}; a["text"] == a.text // true  Testing for object property ”text” in a // true  Enumerating object properties for (var o in window) { console.log(o + ':' + window[o]); }  Array basics        push : adds an element length concat : join 2 arrays join(string) : string represenation of the array split by the argument slice(start, end) : returns elements between args sort ([function]) : sorts by alphabet or by function supplied as arg pop : extracts last element
  • 7. Some bad parts Global variables  window object is shared by everyone  no warning or crash if a variable is overwritten  Easy to end-up with ”function soup”, an unmaintainable mess of global objects & functions (MS Virtual Earth) eval & with var o = {}; with (o) { prop = 2; // prop isn’t defined on object o and ends up on the global object } alert(prop); // 2 == & != typeof semi-colon insertion 0.1 + 0.2 == 0.3 // false (IEEE 754 floating point)
  • 8. Prototype Every function has a prototype, a shared object var sword = function() { this.swing = function(){ console.log(”Swing”); }; }; // Every sword instance will have its own version of swing var sword = function() { }; sword.prototype.swing = function(){ // Every sword created will share this function console.log(”Swing”); }; Use hasOwnProperty to distinguish prototype methods from own properties
  • 9. Execution Scope Scope is the execution context, the this property var obj = { number : 42, showNumber: function () { alert(this.number); } }; obj.showNumber(); // 42 document.body.onclick = obj.showNumber; // clicking the body shows ”undefined” call and apply can bind a new scope to a function var anotherObj = { number : ”blablabla” }; obj.showNumber.call(anotherObj); // ”blablabla”  call (scope, arg1, arg2, ...) apply(scope, [arg1, arg2, ...]) Variable scope: function scope, not block scope for(var i = 0; i<5;i++) {} alert(i); // 5
  • 10. Asynchronous JavaScript and XML Term coined by Jesse James Garret in 2005 XHR added in IE5 through an ActiveX object All browsers (IE7+) supports the XMLHttpRequest object Cross domain restrictions apply IE8 implements XDomainRequests, (does not send cookies)
  • 11. JSON  JavaScript Object Notation  Invented by Douglas Crockford of Yahoo  The preferred data transfer format of the web  More lightweight than XML  { ”property” : ”value”}  Possible value types:        String Number Object Array true false null  eval the JSON to get a native JS object, or use a JSON parser. ECMAScript 3.1 will have native support for JSON.parse and JSON.stringify (already in FF3.1)
  • 12. Debugging FireBug for Firefox(Lite for IE) (1.4 adds JSON viewer) Fiddler (if using http://localhost, use http://localhost.)   JsonViewer plugin SyntaxViewer plugin IE: Internet Options -> Advanced -> Disable script debugging debugger; attaches a client-side debugger IE8 has a developer toolbar builtin, for previous versions there is IE Developer Toolbar
  • 13. Tools  Validators  JsLint  JavaScriptLint  Minifiers  JsMin  Dojo ShrinkSafe  YUI Compressor  Unit testing  JsUnit  YUI Test  Dojo Object Harness  Documentation generators  JsDoc  YUI Doc  Secure execution environments  ADSafe (Crockford)  Caja
  • 14. Performance  YUI Exceptional Performance Team  Use Yslow plugin to FB  If using namespaced objects repeatedly, assign to a local variable first BAD myNS.subNS.obj.prop = 2; myNS.subNS.obj.name = ”Test”; myNS.subNS.obj.index = 2345; BETTER var m = myNS.subNS.obj; m.prop = 2; m.name ....  Even if the JavaScript engines ran at infinite speed, web pages would not run noticeably faster. The DOM operations are typically the culprit when it comes to poor performance.  Read Steve Souders blog on High performance websites
  • 15. Events Events handling in the DOM is tricky, browser implementations vary. Using a JS library that normalizes the event object is very helpful Registering events the old fashioned way (DOM level 0)  <a href="http://www.facebook.com” onclick="return fbs_click(this)">Facebook</a>  element.onclick = function() {}  Only one listener can be registered, last listener assigned wins ”Correct” way of doing this  W3C : element.addEventListener(’click’, fn, [executeInCapturePhase])  IE : element.attachEvent('onclick', fn) // flawed (this points to window in fn, useless)
  • 17. jQuery • • • • Cross-browser javascript library Free & Opensource First released Jan 06 @Barcamp by John Resig Last stable version 1.10.2
  • 18. Why jQuery ? • • • • • • Cross-browser compatibility Fast & Small Plug-in Learning curve & Documentation Intellisense in VS2008-2010 Microsoft [Ajax Lib & MVC]
  • 21. Getting Start • Download jQuery at jquery.com – <script type="text/javascript" src="/js/jQuery. js"></script> • Microsoft CDN or Google CDN – <script src="http://ajax.microsoft.com/ajax/jquery/jquery1.4.2.js" type="text/javascript"></script> – <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jq uery.js"></script>
  • 22. Hello world jQuery • Document ready $(document).ready(function () { alert("Hello world jQuery"); }); // Short cut $(function () { alert("Hello world jQuery"); });
  • 25. Selector • CSS Style – $(“#myID”) // by id – $(“.myClass”) // by class name – $(“myTag”) // by tag (element name) – $(“#id, .class, tag”) // multiple
  • 26. Selector [Hierarchy] • $("form input") // descendant • $("#main > *")// child • $("#prev ~ div") // sibling
  • 27. Selector [Hierarchy] • $("form input") // descendant <form> <div> Form is surrounded by the green outline</div> <label> Child:</label> <input name="name" /> <fieldset> <label> Grandchild:</label> <input name="newsletter" /> </fieldset> </form>
  • 29. Selector [Form] • • • • • • $("div :text") $("form :radio") $("#dvMainForm :checkbox") $(":button") $("input:disabled") $("input:checked")
  • 32. Event • Bind – $(“input”).bind(“blur”, fn); • Trigger – $(“input”).trigger(“focus”); • Event Helper – $(“input”).click(function() { alert(‘click’); }); – S(“input”).click(); • Live – $(“input”).live(“click”, fn);
  • 33. Traversing • • • • find $("p").find("span").css('color','red'); children $("div").children(".selected").css("color); parent $("tr").parent().get(0).tagName; next $("button[disabled]").next().text("this button is disabled"); • prev $("p").prev(".selected").css("background", "yellow"); • sibling $(".hilite").siblings() .css("color", "red")
  • 34. Manipulation • append $ ("p").append("<strong>Hello</strong>"); • appendTo $("span").appendTo("#foo"); • prepend &prependTo • after $("p").after("<b>Hello</b>"); • before $("p").before("<b>Hello</b>");