FEWD Topic 8 - JQuery
FEWD Topic 8 - JQuery
Topic 8:
jQuery
Learning Outcomes
By the end of this topic students will be able to:
• Explain jQuery concepts
• Create animated, interactive web pages using
jQuery library
• Make use of simple jQuery examples
• Explain jQuery Events and Effects
• Describe jQuery UI
jQuery Topic 8 - 8.4
Unit Roadmap
Week Topic Week Topic
Overview of Web
1 Application 7 JavaScript - II
Architecture
Introduction to
2 HTML5 8 jQuery
jQUERY
jQuery Topic 8 - 8.6
Introduction to jQuery
• jQuery is a lightweight, feature rich JavaScript library
Introduction to jQuery
• Most popular and extendable library for websites and mobile single
page app development
• Large companies (ex: Google) use jQuery library and host jQuery
CDN (Both Google and Microsoft)
P3: Extensibility
New events, elements, and methods can be easily added and
reused as a plugin
jQuery Topic 8 - 8.9
jQuery syntax
jQuery syntax is designed to select HTML elements and perform actions
on them.
Syntax: $(selector).action() Selector : this | id | class | element
jQUERY EVENTS
jQuery Topic 8 - 8.11
Selectors
• Selectors are the most basic concept of
jQuery
Selectors - Example
jQuery Topic 8 - 8.17
Element Selectors
Selector Descriptio
$("*") n
Selects all elements
$("#id") Selects an element having identifier as id
$(".class-name") Selects element with class as class-name
$("p:first") Selects first element in a paragraph
$("ul li:first") Selects the first <li> element of the first <ul>
$("[href]") Selects all elements with an href attribute
$(":button") Selects all <button> elements and <input> elements of type="button"
$("tr:even") Selects all even <tr> elements
$("tr:odd") Selects all odd <tr> elements
$("div:gt(2)") All div elements except the first three
jQuery Topic 8 - 8.18
Quiz -1
1. How do you select all elements with the class 'example' using jQuery?
A) $("example")
B) $(".example")
C) $("#example")
Example Events
Selector Description
Mouse click | dbclick | hover | mouseenter | mouseleave
Keyboard keypress | keyup | keydown
Form focus | blur | submit
Window (BOM) load | resize
jQuery Topic 8 - 8.22
Introduction to Effects
• Effects provide more options to operate on an HTML element
Fading Effects
Selector Description
$(selector).fadeIn(speed,callback); It is used to fade in a hidden elements
$(selector).fadeOut(speed,callback); It is used to fade out a visible element
$(selector).fadeToggle(speed,callback); Toggles between the fadeIn() and fadeOut()
methods
$(selector).fadeTo(speed,opacity,callback); Allows fading to a given opacity (value between 0
and 1)
jQuery Topic 8 - 8.26
Sliding Effects
Selector Description
$(selector).slideDown(speed,callback); Slide down an element
$(selector).slideUp(speed,callback); Slide up an element
$(selector).slideToggle(speed,callback); Toggles between the slideDown() and slideUp()
methods
jQuery Topic 8 - 8.28
Sliding Effects
jQuery Topic 8 - 8.29
Animation Effects
Chaining in jQuery
• Multiple jQuery
actions/methods can be
combined together
• It helps to execute multiple
actions using single statement
jQuery Topic 8 - 8.32
Quiz - 2
1. Which method is used to hide an element with a sliding motion in jQuery?
A) slideHide()
B) slideUp()
C) hideSlide()
jQUERY DOM
jQuery Topic 8 - 8.34
DOM APIs
Selector Description
$(selector).text(); Sets or returns the text content of selected elements
$(selector).html(); Sets or returns the content of selected elements (including HTML mark-up)
$(selector).val(); Sets or returns the value of form fields
jQuery Topic 8 - 8.36
Selector Description
$(selector).width(); Sets or returns the width of an element (excludes padding, border and
margin)
$(selector).height(); Sets or returns the height of an element (excludes padding, border and
margin).
$(selector).innerWidth(); Returns the width of an element (includes padding)
$(selector).innerHeight(); Returns the height of an element (includes padding)
$(selector).outerWidth(); Returns the width of an element (includes padding and border)
$(selector).outerHeight(); Returns the height of an element (includes padding and border)
jQuery Topic 8 - 8.40
jQUERY UI
jQuery Topic 8 - 8.43
jQuery UI – draggable()
The jQuery UI draggable() method
makes any DOM element
draggable after which you can drag
it anywhere within the HTML page.
Syntax: $(selector).draggable();
jQuery Topic 8 - 8.44
jQuery UI – droppable()
The jQuery UI droppable() method
makes any DOM element droppable
that can be dropped at a specified
target area on the HTML page.
Syntax: $(selector).droppable();
jQuery Topic 8 - 8.45
jQuery UI – DatePicker
• The jQuery UI datepicker facilitates user to enter dates easily and visually
with an aid of calendar widget
Syntax:
$(selector).datepicker();
jQuery Topic 8 - 8.46
References
Books:
• jQuery Introduction & Syntax
• Chaffer, J., & Swedberg, K. (2013). jQuery in Action. Manning Publications.
• jQuery Events & Effects
• Bibeault, B., & Katz, Y. (2015). Learning jQuery, 3rd Edition. Packt Publishing.
• DOM
• Duckett, J. (2014). JavaScript and JQuery: Interactive Front-End Web Development. John Wiley & Sons.
• jQuery UI
• Libby, A. (2014). jQuery UI in Action. Manning Publications. Web Resources
• jQuery Introduction
• jQuery.com. jQuery Introduction. Available at: jQuery Introduction
• jQuery Syntax
• W3Schools. jQuery Syntax. Available at: W3Schools jQuery Syntax
• jQuery Events
• Mozilla Developer Network (MDN). Introduction to events. Available at: MDN Events
• jQuery Effects
• jQuery.com. jQuery Effects. Available at: jQuery Effects
• DOM
• Mozilla Developer Network (MDN). Introduction to the DOM. Available at: MDN DOM Introduction
• jQuery UI
• jQueryUI.com. jQuery UI. Available at: jQuery UI
Topic 8 – jQuery
Any Questions?