jquery
jquery
Jack G. Zheng
Fall 2019
Overview
l Client side JavaScript frameworks
l jQuery overview
l jQuery basics and examples
l jQuery family resources
2
JavaScript Library
l Why libraries/frameworks?
l “Advanced JavaScript programming (especially the
complex handling of browser differences), can often be
very difficult and time-consuming to work with.”
l Libraries or frameworks promotes reusability and best
practices
l What are the common libraries?
l http://jster.net
l http://en.wikipedia.org/wiki/List_of_JavaScript_libraries
l http://en.wikipedia.org/wiki/Comparison_of_JavaScript_fra
meworks
l https://www.similartech.com/categories/javascript
l https://www.sitepoint.com/top-javascript-frameworks-
libraries-tools-use/
3
Popularity – Why jQuery
Data source:
https://www.similartech.com/categories/javascript
Data source:
• http://w3techs.com/technologies/overview/javascript_library/all
• http://w3techs.com/technologies/cross/javascript_library/ranking 4
jQuery Overview
l What is jQuery?
l jQuery is a JavaScript library designed to simplify
and enrich the client-side scripting.
l http://jquery.com
l Quick facts
l Initial released on August 26, 2006
l Current stable versions: 3.4.1 (as of Aug 27, 2019)
l Cross platform - http://jquery.com/browser-support/
l Light weight - Only about 30KB minified and
compressed.
l http://en.wikipedia.org/wiki/JQuery
5
jQuery Features and Advantages
l Non-obtrusive scripting
l Separates JavaScript and HTML completely: Instead of using HTML attributes to call JavaScript
functions for event handling, jQuery can be used to handle events purely in JavaScript.
l jQuery provides a new paradigm for event handling. The event assignment and the event callback
function definition are done in a single step in a single location in the code.
l https://en.wikipedia.org/wiki/Unobtrusive_JavaScript
l Reusability
l Provides many functions that simplify highly-used JavaScript functionalities like UI effects, string
processing, parse JSON data, AJAX, etc.
l Extensible
l New events, elements, and methods can be easily added and then reused as a plugin.
6
Basic jQuery Usages
l HTML DOM/CSS manipulation
l Provide simpler ways to work with HTML and CSS
elements dynamically
l HTML event methods
l Provide a better way to handle events
l Simple effects and animations
l Provide simple function call for commonly used effects
and animations, such as show/hide, transition, etc.
l AJAX
l Provide more efficient way to handle AJAX calls
l Utility functions
l More functions to handle common tasks
7
Referencing jQuery Library
l Two basic ways used with the <script> tag
l Download the jQuery library files from jQuery.com and include it in
your website.
l Include jQuery from a CDN directly and have the CDN site to serve
jQuery library files.
l http://www.w3schools.com/jquery/jquery_get_started.asp
l CDN (content delivery network)
l A centralized service to provide commonly and publicly used script
libraries
l Faster and more reliable than self-hosting
8
jQuery Basic Syntax
l Basic syntax is: $(selector).action()
l A $ sign to define/access jQuery
l A (selector) to "query (or find)" HTML elements
l A jQuery action() to be performed on the element(s)
l Examples
10
jQuery Events
l Events represents a pre-defined action that happens with a target
l Examples – (full list of events: http://api.jquery.com/category/events/)
l Events
l http://www.w3schools.com/jquery/jquery_events.asp
11
Anonymous Function
l Aligned format style Mouse click event
$("p").click
( Anonymous function to
function() handle the event (when
mouse button clicked)
{
// statements goes here!!
}
);
12
Document Ready Event
l Better to put all scripts inside the document ready event
to prevent any jQuery code from running before the
document is finished loading (is ready).
l Except for defining functions
l https://learn.jquery.com/using-jquery-core/document-
ready/
$(document).ready(function(){ $(function(){
});
14
Effects
l jQuery provides efficient functions to add simple
effects to your page.
l Hide, show
l Slide
l Fading
l Animate
l https://learn.jquery.com/effects/intro-to-effects/
15
jQuery Examples
Some examples are provided to compare the coding with
traditional JavaScript and jQuery. The examples are provided in
D2L and hosted at http://it4203.jackzheng.net/demo/jquery/
16
Advanced Features
l Callback
l http://www.w3schools.com/jquery/jquery_callback.asp
l Chaining
l http://www.w3schools.com/jquery/jquery_chaining.asp
l Code organization
l https://learn.jquery.com/code-organization/
17
jQuery Family
l jQuery UI
l A set of user interface interactions, effects, widgets, and themes built
on top of the jQuery
l http://jqueryui.com
l jQuery Mobile
l An HTML5-based user interface framework to build sites and apps
targeting mobile devices. This framework provides a set of touch-
friendly UI widgets and an AJAX-powered navigation system.
l http://jquerymobile.com
l jQuery Plugins
l https://www.npmjs.com/browse/keyword/jquery-plugin
l http://jquer.in
l Other projects from jQuery Foundation
l https://jquery.org/projects
18
Vanilla JavaScript
l VanillaJS is a name to refer to using plain
JavaScript without any additional libraries like
jQuery.
l See some opposite opinions on using jQuery
l https://snipcart.com/blog/learn-vanilla-javascript-
before-using-js-frameworks
19
More Resources
l Learning resources
l http://www.w3schools.com/jquery/
l http://www.codecademy.com/tracks/jquery
l http://learn.jquery.com
l http://try.jquery.com
l http://jqfundamentals.com
l http://www.jquery-tutorial.net
l Video tutorials
l https://www.youtube.com/playlist?list=PLoYCgNOIyGABdI2V8I_SWo22tFpgh2s6_
l https://www.youtube.com/playlist?list=PLIoX3-mcY80gRbIVp1CJMGG3B0mOd9kDo
l References
l http://api.jquery.com
l http://jqapi.com
20