Upload
designveloper
View
86
Download
0
Tags:
Embed Size (px)
DESCRIPTION
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. (jQuery.com)
Citation preview
Designveloper
JQUERY
Write less, do more
Jquery
▪ jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. (jQuery.com)
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Documentation & Support
API: api.jquery.com Forum: forum.jquery.com IRC: irc.freenode.net, #jquery http://
www.codecademy.com/en/courses/you-and-jquery/0/1
https://www.codeschool.com/courses/try-jquery
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Simple Concept
▪ Find something
▪Do something
FIND SOMETHING
“select” elements in document
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Find something
$()
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Find something
// id selector var elem = $("#myid");
// group selector var elems = $("#myid p");
// context selector var elems = $("#myid > div p");
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
jQuery / javascript comparison
Javascript jquery
getElementById(“id”) $(“#id”)
getElementByClassName(“class”) $(“.class”)
getElementByName(“somename”) $(“[name=‘somename’]”)
getElementByTagName(“tag”) $(“tag”)
querySelector(“selector”) $(“selector”)
Do something
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Do something
1.Let elements "listen" for something to happen
the document is ready user does something another "listener" acts a certain amount of time elapses
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Do something
2.… and then do something
Manipulate elements Animate elements Communicate with the server
Dev Tools
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Text Editors
▪ Eclipse / Aptana
▪Notepad++
▪Visual Studio
▪NetBean
▪ and so on.
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Firefox: firebug
▪ Console
▪ DOM Viewer
▪ JavaScript debugger
▪ Net view
▪ Lots of extensionshttp://getfirebug.com/wiki/index.php/Firebug_Extensions
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Chrome Developer tools
▪ In many ways, leapfrogging Firebug
▪ Live debugging, code changing
▪ Lots of "hidden" goodies
▪ http://code.google.com/chrome/devtools/
▪ Paul Irish screencast: http://youtu.be/nOEw9iiopwI
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The Basic
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The basic
▪ Strings: textual content. wrapped in quotation marks (single or double).
▪ Numbers: integer (2) or floating point (2.4)
▪Booleans: true or false
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The basic
▪Arrays: simple lists. indexed starting with 0– ['Karl', 'Sara', 'Ben', 'Lucia']– ['Karl', 2, 55]– [ ['Karl', 'Sara'], ['Ben', 'Lucia']]
▪Objects: lists of key, value pairs– {firstName: 'Karl', lastName: 'Swedberg'}– {parents: ['Karl', 'Sara'], kids: ['Ben', 'Lucia']}
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The basic
▪Always declare your variables!
▪ If you don't, they will be placed in the global scope .–bad: myName = 'Karl';–good: var myName = 'Karl';–still good: var myName = 'Karl’,
myName = 'Joe';
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The basic
▪ conditionals:– if, else – switch
▪ operators:– +, -, *, %, ++, --– >, <, ==, !=, >=, <=, ===, !==– !, &&, ||
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The basic
LOOP
▪ The two most common loops...– for loops — for general-purpose iteration. Used with
arrays or array-like objects)– for-in loops — used with arrays or objects (but don't
use with arrays)
▪ The other two are...– while loops– do-while loops
function
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
function
▪ Functions allow you to define a block of code, name that block, and then call it later as many times as you want.– function myFunction( ) { /* code goes
here */ } // defining– myFunction( ) // calling the function myFunction
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
function
▪You can define functions with parameters –function myFunction(param1,
param2 ) { /* code goes here */ }▪You can call functions with arguments:–myFunction('one', 'two')
Install
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Download
http://jquery.com/download/
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
Tips
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Tips
▪ Store selectors used more than once in variables
▪ Use length property to check existence– ...but often no need for the check
▪ var listItems = $('li');
▪ var numItems = $listItems.length
//no need for length check
$listItems.addClass('pretty');
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Tips
Concatenate to pass in a variable
$('#menu li').each(function(index) { $(this).click(function() {
$('#footer li:eq(' + index + ')').addClass('active');
});
});
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Tips
▪ Avoid jQuery's custom selectors when possible
// bad$(':checkbox') // better$('input:checkbox')// best$('input[type="checkbox"]')
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Tips
// uncool$('div:first')
// cool$('div').first();
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Tips
// slower$('li:eq(3)')$('li:lt(3)')
// faster$('li').eq(3)$('li').slice(0, 3)
Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
The end
Thank you for listening