SlideShare a Scribd company logo
JQUERY
WRITE LESS, DO MORE
Presented By
Nayab
Sheikh
Introduction to jQuery
• jQuery is a lightweight, open-source
JavaScript library that simplifies
interaction between HTML and
JavaScript
• It was and still being developed
by John Resig from Mozilla and was first
announced in January 2006
• It has a great community, great
documentation, tons of plugins, and it was
recently adopted by Microsoft
The current version is 1.3.2
(as of July 2009)
• Getting Started
• Download the latest version from
http://jquery.com
Copy the
jquery.js
and the
jquery-vsdoc.js
into your application folder
Reference it in your markup
• <script src=“jquery.js”/>
Reference it in your JS files:
• … or just drag it into the file
///<reference
path=“jquery.js”/>
jQuery Core
Concepts
jQuery Basics
• jQuery()
• This function is the heart of the jQuery library
• You use this function to fetch elements using CSS
selectors
• and wrap them in jQuery objects so we can manipulate
• them
• There’s a shorter version of the jQuery() function: $()
• $("h1");
• $(".important");
Document Ready
• $(document).ready(function(){
• // Your code here
• });
• jQuery has a simple statement that checks
the
• document and waits until it's ready to be
manipulated
What’s the problem with
JavaScript?
• JavaScript is a weakly typed, classless,
prototype based OO language, that can
also be used outside the browser. It is
not a browser DOM.
It means no more of this
• var tables =
document.getElementsByTagName("table");
• for (vart = 0; t<tables.length; t++) {
• var rows =
tables[t].getElementsByTagName("tr");
• for (vari = 1; i<rows.length; i += 2) {
• if
(!/(^|s)odd(s|$)/.test(rows[i].className))
{
• rows[i].className += " odd";
• }
• }
• };
Using jQuery we can do this
• $("tabletr:nth
• child(odd)").addClass("odd");
Using jQuery we can do
this
• jQuery("tabletr:ntchild(odd)"
). addClass("odd");
JQUERY FUNCTION
Using jQuery we can do
this
• jQuery("tabletr:nthchild(odd)").add
Class("odd");
JQUERY SELECTOR(CSS EXPRESSION)
Using jQuery we can do
this
• jQuery("tabletr:nth-
child(odd)").addClass("odd");
JQUERY METHOD
Hide divs with pure
JavaScript
• divs =
document.getElementByTagName(‘div’)
;
• for (i = 0; i < divs.length; i++) {
• divs[i].style.display = ‘none’;
• }
Hide divs with jQuery
• $(“div”).hide();
• It really is the
“write less, do more”
JavaScript Library!
Why use jQuery
• Helps us to simplify and speed up web
development
• Allows us to avoid common headaches
associated with browser development
• Provides a large pool of plugins
• Large and active community
• Tested on 50 browsers, 11 platforms
• Its for both coders and designers
how jQuery works?
• The $() function is an alias for the jQuery()
function .
• This returns a special Java-Script object.
• This JavaScript Object contains an array
of DOM elements that matches the selector.
• Selector is key thing in jQuery development.
• It is away to select node from DOM. This
Java-Script object possesses a large number
of useful predefined methods that can action
group of elements.
Starting with Jquery
• We load the Jquery library as any external JavaScript file.
script type="text/javascript"
src="jquery.js"></script>
• Now we loaded the Jquery library
• As almost everything we do when using jQuery reads or
manipulates the document object model (DOM), we need to
make sure that we start adding events etc. as soon as the DOM
is ready.
• To do this, we register a ready event for the document.
$(document).ready(function() {
// do stuff when DOM is ready
});
jQuery Syntax
• The jQuery syntax is tailor made for selecting HTML
elements and perform some action on the
element(s).
• Basic syntax is: $(selector).action()
– A dollar sign to define jQuery
– A (selector) to "query (or find)" HTML elements
– A jQuery action() to be performed on the
element(s)
jQuery Syntax Con,t
• Examples:
– $(this).hide() - hides current element
– $("p").hide() - hides all paragraphs
– $("p.test").hide() - hides all paragraphs with
class="test"
– $("#test").hide() - hides the element with id="test"
Selectors
• With normal JavaScript, finding elements can be extremely
cumbersome, unless you need to find a single element
which has a value specified in the ID attribute.
• jQuery can help you find elements based on their ID,
classes, types, attributes, values of attributes and much,
much more.
• It's based on CSS selectors and as you will see after going
through this that, it is extremely powerful
Selectors(cont’d)
• You can instantiate the jQuery object simply by writing
jQuery() or even shorter using the jQuery shortcut name:
$(). Therefore, selecting a set of elements is as simple as
this:
$(<query here>)
• With the jQuery object returned, you can then start using
and altering the element(s) you have matched.
Select DOM elements
• Selecting DOM elements through document based on the
css selectors.
• The #id selector
$(document).ready(function() {
$(“#d1").text("Test");
});
• This code will be applied on only one element whose ID
attribute is d1.
Select DOM
elements(cont’d)
• The .class selector
$(document).ready(function() {
$(“.para").text("Test");
});
• This code will be applied on all elements with the .para
class
Select DOM
elements(cont’d)
• The element selector
$(document).ready(function() {
$(“div").text("Test");
});
• This code will be applied on all <div> tags
Select DOM
elements(cont’d)
$(document).ready(function() {
$("#d2 span").text("Test");
});
• This code will be applied on all span elements within
the element whose ID attribute is #d2.
$(document).ready(function() {
$("span.bold").text("Test");
});
• This will match all span elements with "bold" as the
class
Some More Examples
• Syntax Description
• $(this) Current HTML element
• $("p) All <p> elements
• $("p.intro") All <p> elements with class="intro"
• $("p#intro") All <p> elements with id="intro"
• $("p.intro:first“) The first <p> element with class="intro"
• $(".intro“) All elements with class="intro"
• $("ul li:first") The first <li> element of the first <ul>
Find elements with a
specific attribute
• The most basic task when selecting elements
based on attributes is to find all the elements
which has a specific attribute.
• The syntax for this selector is a set of square
brackets with the name of the desired attribute
inside it, for instance [name] or [href].
Find elements with a
specific attribute(cont’d)
• Example.
$(document).ready(function() {
$(“[id]").text("Test");
});
• We use the attribute selector to find all elements on the
page which has an id attribute and then add text to it. As
mentioned, this will match elements with an id element no
matter what their value is
jQuery Events
• The jQuery event handling methods are core functions in
jQuery.
• Event handlers are method that are called when "something
happens" in HTML. The term "triggered (or "fired") by an
event" is often used.
• $("button").click(function() {..some code... } )
• EX:
– $(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
jQuery Events(cont’d)
• Here are some examples of event methods in jQuery:
• Event Method Description
• $(document).ready(function) Binds a function to the ready event of a
document
(when the document is finished loading)
• $(selector).click(function) Triggers, or binds a function to the click
event of selected elements
• $(selector).dblclick(function) Triggers, or binds a function to the
double click event of selected elements
A Few Examples
 Forms
 Chatboxes
 Menus
 Dropdowns
 Sliders
 Tabs
 Slideshows
 Games
jQuery Enhanced Forms
Menus and Dropdowns
Sliders and Slideshows
Pros:
• Large Community
• Ease of use
• Large library
• Strong opensource community. (Several
jQuery plugins available)
• Great documentation and tutorials
• Ajax support
Cons:
• Regular updates that change existing
behaviour
• Overhead of adding extra javascript to
page
• Learning curve may not be short for some
developers
Conclusions
• Conclusion In the end, jquery is popular for a
reason. It will make your website easier to control
and to access through any browser.
• By using this library, you can create or include
complex plug-ins in a matter of minutes. This will
make your website easier to use and as long as you
have imagination, the possibilities are endless.
Thank You

More Related Content

What's hot (20)

PDF
jQuery for beginners
Siva Arunachalam
 
PPTX
jQuery
Vishwa Mohan
 
PPT
JQuery introduction
NexThoughts Technologies
 
PDF
jQuery Essentials
Marc Grabanski
 
PPTX
jQuery Presentasion
Mohammad Usman
 
PPTX
jQuery Presentation
Rod Johnson
 
PPT
jQuery
Mostafa Bayomi
 
PDF
Learn css3
Mostafa Bayomi
 
PDF
D3.js and SVG
Karol Depka Pradzinski
 
PPTX
jQuery from the very beginning
Anis Ahmad
 
PDF
jQuery Introduction
Arwid Bancewicz
 
KEY
jQuery Selectors
jQuerySlideCasts
 
PDF
jQuery Rescue Adventure
Allegient
 
PPTX
Jquery-overview
Isfand yar Khan
 
PPTX
How to increase Performance of Web Application using JQuery
kolkatageeks
 
PDF
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
PPTX
JQuery
Jacob Nelson
 
PPTX
Jquery introduction
musrath mohammad
 
jQuery for beginners
Siva Arunachalam
 
jQuery
Vishwa Mohan
 
JQuery introduction
NexThoughts Technologies
 
jQuery Essentials
Marc Grabanski
 
jQuery Presentasion
Mohammad Usman
 
jQuery Presentation
Rod Johnson
 
Learn css3
Mostafa Bayomi
 
D3.js and SVG
Karol Depka Pradzinski
 
jQuery from the very beginning
Anis Ahmad
 
jQuery Introduction
Arwid Bancewicz
 
jQuery Selectors
jQuerySlideCasts
 
jQuery Rescue Adventure
Allegient
 
Jquery-overview
Isfand yar Khan
 
How to increase Performance of Web Application using JQuery
kolkatageeks
 
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
JQuery
Jacob Nelson
 
Jquery introduction
musrath mohammad
 

Viewers also liked (6)

PPT
Intro to jQuery - Tulsa Ruby Group
Brad Vernon
 
PPT
jquery examples
Danilo Sousa
 
PPT
jQuery Conference 2010 - Getting Involved
Ralph Whitbeck
 
PPT
Intro to jQuery
Ralph Whitbeck
 
PPT
WordCamp London 2013
Ivelina Dimova
 
PDF
J query 17-visual-cheat-sheet
Renuka Prasad Yarasu
 
Intro to jQuery - Tulsa Ruby Group
Brad Vernon
 
jquery examples
Danilo Sousa
 
jQuery Conference 2010 - Getting Involved
Ralph Whitbeck
 
Intro to jQuery
Ralph Whitbeck
 
WordCamp London 2013
Ivelina Dimova
 
J query 17-visual-cheat-sheet
Renuka Prasad Yarasu
 
Ad

Similar to Jquery (20)

PDF
Introduction to jQuery
Seble Nigussie
 
PPTX
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
PPTX
J query
Ramakrishna kapa
 
PPTX
JQuery_and_Ajax.pptx
AditiPawale1
 
PPTX
Web technologies-course 11.pptx
Stefan Oprea
 
PPTX
Getting Started with jQuery
Laila Buncab
 
PPTX
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
PPTX
jQuery besic
Syeful Islam
 
PDF
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
ODP
Jquery- One slide completing all JQuery
Knoldus Inc.
 
PPTX
Unit3.pptx
AnamikaRai59
 
PPT
J query lecture 1
Waseem Lodhi
 
PDF
Advanced JQuery Mobile tutorial with Phonegap
Rakesh Jha
 
PDF
Javascript libraries
Dumindu Pahalawatta
 
PPTX
Introduction to jquery mobile with Phonegap
Rakesh Jha
 
PPTX
presentation_jquery_ppt.pptx
azz71
 
PPTX
jQuery
PumoTechnovation
 
PPTX
Getting Started with jQuery
Akshay Mathur
 
PPT
Jquery PPT_Finalfgfgdfgdr5tryeujkhdwappt
shubhangimalas1
 
PPTX
Introduction to JQuery
Muhammad Afzal Qureshi
 
Introduction to jQuery
Seble Nigussie
 
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
JQuery_and_Ajax.pptx
AditiPawale1
 
Web technologies-course 11.pptx
Stefan Oprea
 
Getting Started with jQuery
Laila Buncab
 
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
jQuery besic
Syeful Islam
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Unit3.pptx
AnamikaRai59
 
J query lecture 1
Waseem Lodhi
 
Advanced JQuery Mobile tutorial with Phonegap
Rakesh Jha
 
Javascript libraries
Dumindu Pahalawatta
 
Introduction to jquery mobile with Phonegap
Rakesh Jha
 
presentation_jquery_ppt.pptx
azz71
 
Getting Started with jQuery
Akshay Mathur
 
Jquery PPT_Finalfgfgdfgdr5tryeujkhdwappt
shubhangimalas1
 
Introduction to JQuery
Muhammad Afzal Qureshi
 
Ad

Recently uploaded (20)

PDF
Cybersecurity of all the online works.pdf
gurjitvirk111
 
PPTX
Fun Friday Ses 2.pptx Ses 2.pptxSes 2.pptxSes 2.pptxSes 2.pptxSes 2.pptx
Naveen124170
 
PPTX
一比一原版(UNE毕业证)新英格兰大学毕业证如何办理
Taqyea
 
PDF
surgical audit in general sirgerymbbs .pdf
suhaasaggarwal300
 
PPTX
EUTHANASIA---Student-Copy.pdwede3dededededptx
oladokunrachel
 
PDF
The Impact of Financial Management on School Performance (www.kiu.ac.ug)
publication11
 
PDF
Macciola_ICDL_Certificato ICDL Base_2575602_240510_151304.pdf
Emanuele915564
 
PDF
Presentation 11 (1).pdf critical thinking in every field of life
riashehnaz
 
PDF
Tycoons Leading the Way in Philanthropy.pdf
Rabbi Ranon Teller
 
PDF
Fresh Porn.pdf Fresh Porn Fresh Porn Fresh Porn
JohnFelix45
 
PDF
_Smarter Hiring Starts with Better Sourcing Platforms.pdf
vinay salarite
 
PDF
Rich Bergeron's Detailed Creative Writing Resume
Rich Bergeron
 
PDF
lecture2-180129175419 (1).pdfhhhhhhhhhhh
zoobiarana76
 
PDF
Sarah Warren Professional Career Overview
Sarah Warren
 
PPTX
climate_change_global_action_and_local_responsibility_xev18307.pptx
hamdeyadd
 
PDF
Active and Passive voice PPT (2).pdf12345
KARTIKSHARMAKK
 
PPTX
iotarchitecture-18018890087605161247.pptx
revathi148366
 
DOCX
Guia de aprendizaje de inglés de quinto nivel
juicsh01
 
PDF
Question and Answers PDF.pdf hhhjjkjjjjjtggggg
ddnarender
 
PPTX
Blue and White Modern Personal Portfolio Presentation.pptx
manansalacoleen0720
 
Cybersecurity of all the online works.pdf
gurjitvirk111
 
Fun Friday Ses 2.pptx Ses 2.pptxSes 2.pptxSes 2.pptxSes 2.pptxSes 2.pptx
Naveen124170
 
一比一原版(UNE毕业证)新英格兰大学毕业证如何办理
Taqyea
 
surgical audit in general sirgerymbbs .pdf
suhaasaggarwal300
 
EUTHANASIA---Student-Copy.pdwede3dededededptx
oladokunrachel
 
The Impact of Financial Management on School Performance (www.kiu.ac.ug)
publication11
 
Macciola_ICDL_Certificato ICDL Base_2575602_240510_151304.pdf
Emanuele915564
 
Presentation 11 (1).pdf critical thinking in every field of life
riashehnaz
 
Tycoons Leading the Way in Philanthropy.pdf
Rabbi Ranon Teller
 
Fresh Porn.pdf Fresh Porn Fresh Porn Fresh Porn
JohnFelix45
 
_Smarter Hiring Starts with Better Sourcing Platforms.pdf
vinay salarite
 
Rich Bergeron's Detailed Creative Writing Resume
Rich Bergeron
 
lecture2-180129175419 (1).pdfhhhhhhhhhhh
zoobiarana76
 
Sarah Warren Professional Career Overview
Sarah Warren
 
climate_change_global_action_and_local_responsibility_xev18307.pptx
hamdeyadd
 
Active and Passive voice PPT (2).pdf12345
KARTIKSHARMAKK
 
iotarchitecture-18018890087605161247.pptx
revathi148366
 
Guia de aprendizaje de inglés de quinto nivel
juicsh01
 
Question and Answers PDF.pdf hhhjjkjjjjjtggggg
ddnarender
 
Blue and White Modern Personal Portfolio Presentation.pptx
manansalacoleen0720
 

Jquery

  • 1. JQUERY WRITE LESS, DO MORE Presented By Nayab Sheikh
  • 2. Introduction to jQuery • jQuery is a lightweight, open-source JavaScript library that simplifies interaction between HTML and JavaScript
  • 3. • It was and still being developed by John Resig from Mozilla and was first announced in January 2006
  • 4. • It has a great community, great documentation, tons of plugins, and it was recently adopted by Microsoft
  • 5. The current version is 1.3.2 (as of July 2009)
  • 7. • Download the latest version from http://jquery.com
  • 9. Reference it in your markup • <script src=“jquery.js”/>
  • 10. Reference it in your JS files: • … or just drag it into the file ///<reference path=“jquery.js”/>
  • 12. jQuery Basics • jQuery() • This function is the heart of the jQuery library • You use this function to fetch elements using CSS selectors • and wrap them in jQuery objects so we can manipulate • them • There’s a shorter version of the jQuery() function: $() • $("h1"); • $(".important");
  • 13. Document Ready • $(document).ready(function(){ • // Your code here • }); • jQuery has a simple statement that checks the • document and waits until it's ready to be manipulated
  • 14. What’s the problem with JavaScript? • JavaScript is a weakly typed, classless, prototype based OO language, that can also be used outside the browser. It is not a browser DOM.
  • 15. It means no more of this • var tables = document.getElementsByTagName("table"); • for (vart = 0; t<tables.length; t++) { • var rows = tables[t].getElementsByTagName("tr"); • for (vari = 1; i<rows.length; i += 2) { • if (!/(^|s)odd(s|$)/.test(rows[i].className)) { • rows[i].className += " odd"; • } • } • };
  • 16. Using jQuery we can do this • $("tabletr:nth • child(odd)").addClass("odd");
  • 17. Using jQuery we can do this • jQuery("tabletr:ntchild(odd)" ). addClass("odd"); JQUERY FUNCTION
  • 18. Using jQuery we can do this • jQuery("tabletr:nthchild(odd)").add Class("odd"); JQUERY SELECTOR(CSS EXPRESSION)
  • 19. Using jQuery we can do this • jQuery("tabletr:nth- child(odd)").addClass("odd"); JQUERY METHOD
  • 20. Hide divs with pure JavaScript • divs = document.getElementByTagName(‘div’) ; • for (i = 0; i < divs.length; i++) { • divs[i].style.display = ‘none’; • }
  • 21. Hide divs with jQuery • $(“div”).hide();
  • 22. • It really is the “write less, do more” JavaScript Library!
  • 23. Why use jQuery • Helps us to simplify and speed up web development • Allows us to avoid common headaches associated with browser development • Provides a large pool of plugins • Large and active community • Tested on 50 browsers, 11 platforms • Its for both coders and designers
  • 24. how jQuery works? • The $() function is an alias for the jQuery() function . • This returns a special Java-Script object. • This JavaScript Object contains an array of DOM elements that matches the selector. • Selector is key thing in jQuery development. • It is away to select node from DOM. This Java-Script object possesses a large number of useful predefined methods that can action group of elements.
  • 25. Starting with Jquery • We load the Jquery library as any external JavaScript file. script type="text/javascript" src="jquery.js"></script> • Now we loaded the Jquery library • As almost everything we do when using jQuery reads or manipulates the document object model (DOM), we need to make sure that we start adding events etc. as soon as the DOM is ready. • To do this, we register a ready event for the document. $(document).ready(function() { // do stuff when DOM is ready });
  • 26. jQuery Syntax • The jQuery syntax is tailor made for selecting HTML elements and perform some action on the element(s). • Basic syntax is: $(selector).action() – A dollar sign to define jQuery – A (selector) to "query (or find)" HTML elements – A jQuery action() to be performed on the element(s)
  • 27. jQuery Syntax Con,t • Examples: – $(this).hide() - hides current element – $("p").hide() - hides all paragraphs – $("p.test").hide() - hides all paragraphs with class="test" – $("#test").hide() - hides the element with id="test"
  • 28. Selectors • With normal JavaScript, finding elements can be extremely cumbersome, unless you need to find a single element which has a value specified in the ID attribute. • jQuery can help you find elements based on their ID, classes, types, attributes, values of attributes and much, much more. • It's based on CSS selectors and as you will see after going through this that, it is extremely powerful
  • 29. Selectors(cont’d) • You can instantiate the jQuery object simply by writing jQuery() or even shorter using the jQuery shortcut name: $(). Therefore, selecting a set of elements is as simple as this: $(<query here>) • With the jQuery object returned, you can then start using and altering the element(s) you have matched.
  • 30. Select DOM elements • Selecting DOM elements through document based on the css selectors. • The #id selector $(document).ready(function() { $(“#d1").text("Test"); }); • This code will be applied on only one element whose ID attribute is d1.
  • 31. Select DOM elements(cont’d) • The .class selector $(document).ready(function() { $(“.para").text("Test"); }); • This code will be applied on all elements with the .para class
  • 32. Select DOM elements(cont’d) • The element selector $(document).ready(function() { $(“div").text("Test"); }); • This code will be applied on all <div> tags
  • 33. Select DOM elements(cont’d) $(document).ready(function() { $("#d2 span").text("Test"); }); • This code will be applied on all span elements within the element whose ID attribute is #d2. $(document).ready(function() { $("span.bold").text("Test"); }); • This will match all span elements with "bold" as the class
  • 34. Some More Examples • Syntax Description • $(this) Current HTML element • $("p) All <p> elements • $("p.intro") All <p> elements with class="intro" • $("p#intro") All <p> elements with id="intro" • $("p.intro:first“) The first <p> element with class="intro" • $(".intro“) All elements with class="intro" • $("ul li:first") The first <li> element of the first <ul>
  • 35. Find elements with a specific attribute • The most basic task when selecting elements based on attributes is to find all the elements which has a specific attribute. • The syntax for this selector is a set of square brackets with the name of the desired attribute inside it, for instance [name] or [href].
  • 36. Find elements with a specific attribute(cont’d) • Example. $(document).ready(function() { $(“[id]").text("Test"); }); • We use the attribute selector to find all elements on the page which has an id attribute and then add text to it. As mentioned, this will match elements with an id element no matter what their value is
  • 37. jQuery Events • The jQuery event handling methods are core functions in jQuery. • Event handlers are method that are called when "something happens" in HTML. The term "triggered (or "fired") by an event" is often used. • $("button").click(function() {..some code... } ) • EX: – $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); });
  • 38. jQuery Events(cont’d) • Here are some examples of event methods in jQuery: • Event Method Description • $(document).ready(function) Binds a function to the ready event of a document (when the document is finished loading) • $(selector).click(function) Triggers, or binds a function to the click event of selected elements • $(selector).dblclick(function) Triggers, or binds a function to the double click event of selected elements
  • 39. A Few Examples  Forms  Chatboxes  Menus  Dropdowns  Sliders  Tabs  Slideshows  Games
  • 43. Pros: • Large Community • Ease of use • Large library • Strong opensource community. (Several jQuery plugins available) • Great documentation and tutorials • Ajax support
  • 44. Cons: • Regular updates that change existing behaviour • Overhead of adding extra javascript to page • Learning curve may not be short for some developers
  • 45. Conclusions • Conclusion In the end, jquery is popular for a reason. It will make your website easier to control and to access through any browser. • By using this library, you can create or include complex plug-ins in a matter of minutes. This will make your website easier to use and as long as you have imagination, the possibilities are endless.