Jquery
Upcoming SlideShare
Loading in...5
×
 

Jquery

on

  • 1,664 views

 

Statistics

Views

Total Views
1,664
Views on SlideShare
1,664
Embed Views
0

Actions

Likes
0
Downloads
20
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Jquery is totally awesome. <br /> I hate how expensive trainings are. So I wanted to give you all training here today that’s priceless. <br /> I really like to learn things at meetings <br />
  • Open Source JavaScript framework. <br /> Jquery was created by John Resig in 2006 and since then has exploded into popularity in the web community. <br />
  • It uses CSS rules to grab DOM elements that&apos;s why its so easy to use, because we all know how to address com elements with css already. <br /> Its really small, it loads really fast in most browsers. <br /> The community is great. I had a question once about how to do something for the new homepage. I asked the question before i left work and had a response by my ride home. <br /> And its compatible with most major browsers. If you make something that works in FF itll work in IE6 guaranteed. <br />
  • Swf object is for putting flash on a page, the closest actual pure JavaScript framework is prototype. <br /> And don’t forget that jQueryUI, a part of jQuery is included in this list, above even mootools. <br />
  • You can see this list on their website. <br /> Microsoft just announced that they are going to be dedicating coder time and resources to improving jQuery core, and its plugins. This is HUGE. <br /> Mention anti microsoft sentiment, and the fact that even microsoft wants IE6 to die. <br />
  • So I mentioned the DOM before, what exactly is the DOM? <br />
  • The Document Object Model. <br /> The DOM is everything you write in your html documents, images, css, all your tags, everything. <br /> The DOM is a mess. There are a million different ways to accomplish things within it and many different doctypes and uppercase and lowercase are allowed attributes that sometimes need quotes, and othertimes don’t. jQuery is coded around all those inconsistencies. <br /> jQuery can modifiy the DOM, but it cant do so untill the DOM is ready. <br />
  • So we wrap all our jQuery code inside some code. Its called the document ready function, and it is only run after all your page has loaded. <br /> Shorthand is <br /> $(function(){ <br /> }); <br />
  • #1 is closer to 99% <br />
  • Loading from the CDN’s is usually the fastest way, because if you are downloading from one place, you can be downloading from another place at the same time. <br /> We usually load it on our servers. <br />
  • Load at the bottom f the page because when the browser is downloading javascripts it blocks everything else <br /> So lets light the fuse now… <br />
  • So lets see what we’re up against. <br /> We begin with a plain P tag and end with a p tag with a class of isCool <br /> Lets break it down on the next page <br /> DEMO <br />
  • We check for the DOM to be ready by the $(function() wrapper <br /> We use the $ to initialize a jquery function <br /> Then we surround a CSS selector with parenthesis and quotes (all P’s will be selected) <br /> Then I initiate a jquery method called addClass and tell it what class to add. <br /> It&apos;s a good thing to note that I don&apos;t add a . Before isCool when adding removing classes. Most methods are alike in how they are called, be careful to check to api to see how to use each method. <br /> I end with a semicolon just like most lines of javascript code <br /> And then close the document ready wrapper <br /> Double quotes can be swapped with single quotes. Same rules apply as normal html or javascript, if you use one you have to end one before switching to the other. <br />
  • Here you can see some of the basic css selectors supported by jquery <br /> Simple things that you&apos;ve seen a lot before. <br /> Div p classes etc <br /> In order to not select everything, make sure to be specific with your CSS selector <br />
  • I want to make this p tag classy, <br /> So I’m going to use the addClass method on it and add the sophisticated class to it you see the before and after html <br /> Note the lack of . Before the class name, that’s only needed for selection <br />
  • I remove classes with a different method, but the way in which I do it stays the same. <br /> If there were other classes on the p tag they would stay intact <br /> DEMO <br />
  • You can show a div by running the show method. <br /> There is a hide method as well. <br /> DEMO <br />
  • Text will change the inner text of a DOM element <br /> DEMO. <br />
  • Methods can be separated across multiple lines. Or kept on the same line <br /> This is a best practice for code readability <br /> Make sure you end your chain with a semicolon; <br /> DEMO <br />
  • Plenty of examples of basic methods within jQuery. <br />
  • Questions so far about 15 minutes <br />
  • Lets get into the meat of jQuery for beginners <br />
  • Trust me on this <br />
  • All demos are on JS Bin. It’s a javascript sandbox that allows you to edit my code examples directly. <br />

Jquery Jquery Presentation Transcript

  • 1 Girish Srivastava girish092.ch@gmail.com
  • Objective  In this tutorial, we will learn everything about the jQuery. After completing the tutorial you will be able to understand about jQuery.  This jQuery tutorial covers: Introduction to jQuery  Features of jQuery  Comparison between different tool kits  Jquery Selectors  2
  • What’s the problem ? with JavaScript
  • JavaScript was a initially introduced in Netscape 2.0B3 in Dec 1995, LiveScript, Jscript, however, it’s official name is ECMAScript
  • JavaScript is a C-family, world’s worst named, extremely powerful language (not a script), totally unrelated to Java
  • JavaScript is a weakly typed, classless, prototype based OO language, that can also be used outside the browser. It is not a browser DOM.
  • The world’s most misunderstood programming language. (Douglas Crockford)
  • Browser DOM really sucks, and this is where jQuery comes to rescue.
  • This session is about improving your Quality of Life !
  • Introduction to jQuery
  • A Little Bit About jQuery What is jQuery? •jQuery is an Open-Source JavaScript framework that simplifies crossbrowser client side scripting. • Animations • DOM manipulation • AJAX • Extensibility through plugins •jQuery was created by John Resig and released 01/06 •Most current release is 1.7.2 (3/19/12) 11
  • A Little Bit About jQuery Why should you use it? •Easy to learn! It uses CSS syntax for selection •Its tiny 71KB (24KB, minified and Gzipped) •Documented api.jquery.com & Supported forum.jquery.com •Cross browser compatibility: IE 6+, FF 2+ •It is the most used JavaScript library on the web today • 39% of all sites that use JavaScript use jQuery.  trends.builtwith.com/javascript/JQuery <- See, I'm not a liar.. 12
  • Features Of Jquery.  jQuery includes the following features:  DOM element selections using the cross-browser open source selector engine Sizzle, a spin- off out of the jQuery project  DOM traversal and modification (including support for CSS 1-3)  DOM manipulation based on CSS selectors that uses node elements name and node elements attributes (id and class) as criteria to build selectors  Events  Effects and animations  Ajax  Extensibility through plug-ins  Cross-browser support 13
  • All Other Frameworks 14
  • Who Uses jQuery? docs.jquery.com/Sites_Using_jQuery 15
  • JQuery versus Dojo versus YUI 16
  • 17
  • When we compare these 3 libraries/frameworks, I found the following which was quite useful. http://selectors.turnwheel.com/slickspeed.php 18
  • jQuery vs MooTools Library Size jQuery Core 55.9K MooTools Core 64.3K Features License DOM Utilites MIT & GPL yes MIT yes Animation Event Handling yes yes yes yes CSS3 Selectors Ajax yes (a subset) yes yes (a subset) yes Native Extensions (excluding about a dozen for Array, Element) Object, and String about six dozen for Array, Object, String, Function, and Number Inheritance Provided with Class  constructor 19 Not supported directly with jQuery
  • The Mottos Say It All If you go to the jQuery site, here's what it says at the top of the page: o jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. ...and if you go to MooTools, this is what you'll find: o MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API. 20
  • 21
  • Historical trend  This diagram shows the historical trend in the percentage of websites using JQuery. 22
  • position  This diagram shows the market positions in terms of popularity and traffic of the 5 most popular JavaScript libraries.  23
  • What is the DOM? Document Object Model (DOM): noun Blah blah blah long definition that makes little sense…. 24
  • What Is The DOM?  Long story short, the DOM is your html document code. From the  <!DOCTYPE> to the </html>  The DOM is loaded top to bottom, so include your scripts at the bottom of the page for best performance.  The DOM is "ready" when everything on the page has loaded. • Stylesheets • JavaScripts • Images 25
  • Wait!!  In order to make sure that jQuery can find the element you asked it for, your browser needs to have loaded it (the DOM needs to be ready).  Q. How can I be sure my code runs at DOM ready?  A. Wrap all your jQuery code with the document ready function: $(document).ready(function(){  }); 26 // insert sweet, sweet jQuery code here…
  • And What If I Don't Wanna, Huh? 1 of 3 things will happen: 1. Code doesn't work, throws an error (90%) Code works… this page load, next page load see #1. (~9%) 3. Code opens a worm hole that transports your page back to 1990 revolutionizing the Web as we know it. While seemingly great, it also creates a paradox and destroys the universe. * (<1%) 2.  27 *(has yet to be fully verified)
  • jQuery Core Concepts
  • The Magic $() function var el = $(“<div/>”) Create HTML elements on the fly
  • The Magic $() function $(window).width() Manipulate existing DOM elements
  • The Magic $() function $(“div”).hide(); $(“div”, $(“p”)).hide(); Selects document elements (more in a moment…)
  • The Magic $() function $(function(){…}); Fired when the document is ready for programming. Better use the full syntax: $(document).ready(function(){…});
  • Loading jQuery In order to use jQuery you need to load it. You can include it locally on your own server:  <script src="/js/jquery.js"> Or use one of the CDN's made available:  ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js  ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js  CDN's are Gzipped and minified 33
  • Load Scripts At The Bottom Problem: When scripts are downloading they block everything else in almost all browsers! Solution: Best practice: Load your scripts at the bottom of your page so they don't interrupt page content downloads. 34
  • 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) 35
  • Three Major Concepts of jQuery The $() function Get > Act Chainability
  • jQuery Selectors
  • All Selector $(“*”) // find everything Selectors return a pseudo-array of jQuery elements
  • Basic Selectors By Tag: $(“div”) // <div>Hello jQuery</div> By ID: $(“#usr”) // <span id=“usr”>John</span> By Class: $(“.menu”) // <ul class=“menu”>Home</ul> Yes, jQuery implements CSS Selectors!
  • And BOOM! Goes The Dynamite. jsbin.com/ecayo3/18#slide19 Html: <p>Hello World! I'm Eric</p> Script: $(function(){ $("p").addClass("isCool"); //keep telling yourself that.. }); Resulting html: <p class="isCool">Hello World! I'm Eric</p> 40
  • Break It Down Now! $(function(){// = $(document).ready(function(){ $ }); 41 ("p") .addClass("isCool");
  • All Your Basic Selectors Are Belong To Us Uses the same syntax you use to style elements in CSS! api.jquery.com/category/selectors/ 42
  • Get Classy <p> jsbin.com/ecayo3/18#slide22 jQuery: $("p").addClass("sophisticated"); Before: <p> After: <p class="sophisticated"> 43
  • This <p> Has No Class At All! jQuery: $("p").removeClass("sophisticated"); Before: <p class="sophisticated"> After: <p class=""> 44
  • <div> Hide and Seek jQuery: $("div").show(); Before: <div style="display:none;"> After: <div style="display:block;"> 45
  • I’m Not Lame, Am I? jQuery: $("#eric").text("Is Cool"); Before: <p id="eric">Is Lame</p> After: <p id="eric">Is Cool</p> 46
  • You Can Chain Most Methods Together $("p")    47 .addClass("sophisticated") .text("Hello World!") .show();
  • Some of Basic Methods api.jquery.com/ 48
  • A Simple Example:  <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> </body> </html> 49
  • Downloading jQuery Two versions of jQuery are available for downloading: one minified and one uncompressed (for debugging or reading). Both versions can be downloaded from  http://docs.jquery.com/Downloading_jQuery#Download_jQuery 50
  • Alternatives to Downloading If you don't want to store the jQuery library on your own computer, you can use the hosted jQuery library from Google or Microsoft. Google <head> <script type="text/javascript" src="http://ajax.googleapis.c om/ajax/libs/jquery/1.4.2/jq uery.min.js"></script> </head> 51 Microsoft <head> <script type="text/javascript" src="http://ajax.microsoft.c om/ajax/jquery/jquery1.4.2.min.js"></script> </head>
  • Questions? http://www.jquerymagic.com/ 52
  • Plugins 53
  • Viva Variety! “If you want to create an animation, effect or UI component, chances are pretty good that someone has done your work for you already.” plugins.jquery.com 54
  • Great References John Resig's introduction slides jQuery 1.4 Cheat Sheet jQuery API jQuery Forums YAYquery Podcast (explicit) http://docs.jquery.com/How_ jQuery_Works DEMOS: jsbin.com/ecayo3/18 55
  • I Like Plugins! Show Us More! 56
  • For any queries mail: girish092.ch@gmail.com 57