33
Designveloper JQUERY Write less, do more

Jquery

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

Page 1: Jquery

Designveloper

JQUERY

Write less, do more

Page 2: Jquery

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

Page 3: Jquery

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

Page 4: Jquery

Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Simple Concept

▪ Find something

▪Do something

Page 5: Jquery

FIND SOMETHING

“select” elements in document

Page 6: Jquery

Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Find something

$()

Page 7: Jquery

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");

Page 8: Jquery

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”)

Page 9: Jquery

Do something

Page 10: Jquery

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

Page 11: Jquery

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

Page 12: Jquery

Dev Tools

Page 13: Jquery

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.

Page 14: Jquery

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

Page 15: Jquery

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

Page 16: Jquery

Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

The Basic

Page 17: Jquery

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

Page 18: Jquery

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']}

Page 19: Jquery

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';

Page 20: Jquery

Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

The basic

▪ conditionals:– if, else – switch

▪ operators:– +, -, *, %, ++, --– >, <, ==, !=, >=, <=, ===, !==– !, &&, ||

Page 21: Jquery

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

Page 22: Jquery

function

Page 23: Jquery

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

Page 24: Jquery

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')

Page 25: Jquery

Install

Page 26: Jquery

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>

Page 27: Jquery

Tips

Page 28: Jquery

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');

Page 29: Jquery

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');

});

});

Page 30: Jquery

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"]')

Page 31: Jquery

Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Tips

// uncool$('div:first')

// cool$('div').first();

Page 32: Jquery

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)

Page 33: Jquery

Website: designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

The end

Thank you for listening