Get Learning Jquery 3 Build Interesting Interactive Sites Using Jquery by Automating Common Tasks and Simplifying The Complicated Ones 2017 5e by Adam Boduch Free All Chapters
Get Learning Jquery 3 Build Interesting Interactive Sites Using Jquery by Automating Common Tasks and Simplifying The Complicated Ones 2017 5e by Adam Boduch Free All Chapters
com
https://textbookfull.com/product/responsive-web-design-by-example-
embrace-responsive-design-with-html5-css3-javascript-jquery-and-
bootstrap-4-hussain/
textbookfull.com
https://textbookfull.com/product/jquery-ui-1-10-the-user-interface-
library-for-jquery-1st-edition-libby-alex-wellman-dan/
textbookfull.com
The Great Free Trade Myth: British Foreign Policy And East
Asia Since 1980 Michael Reilly
https://textbookfull.com/product/the-great-free-trade-myth-british-
foreign-policy-and-east-asia-since-1980-michael-reilly/
textbookfull.com
Security Operations Center Guidebook A Practical Guide for
a Successful SOC Gregory Jarpey
https://textbookfull.com/product/security-operations-center-guidebook-
a-practical-guide-for-a-successful-soc-gregory-jarpey/
textbookfull.com
https://textbookfull.com/product/heart-and-soul-shayne-davies-3-1st-
edition-jackie-may/
textbookfull.com
https://textbookfull.com/product/endemic-disease-in-china-dianjun-sun/
textbookfull.com
https://textbookfull.com/product/british-sociologists-and-french-
sociologues-in-the-interwar-years-the-battle-for-society-baudry-
rocquin/
textbookfull.com
https://textbookfull.com/product/the-cambridge-handbook-of-social-
problems-volume-2-1st-edition-a-javier-trevino/
textbookfull.com
OAuth 2 in Action 1st Edition Justin Richer
https://textbookfull.com/product/oauth-2-in-action-1st-edition-justin-
richer/
textbookfull.com
Title Page
Learning jQuery 3
Fifth Edition
BIRMINGHAM - MUMBAI
https://avxhm.se/blogs/AlenMiler
Copyright
Learning jQuery 3
Fifth Edition
Copyright © 2017 Packt Publishing
Every effort has been made in the preparation of this book to ensure
the accuracy of the information presented. However, the information
contained in this book is sold without warranty, either express or
implied. Neither the authors, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or
alleged to be caused directly or indirectly by this book.
ISBN 978-1-78588-298-2
www.packtpub.com
https://avxhm.se/blogs/AlenMiler
Credits
Authors
Karl Swedberg
I'd like to thank John Resig for creating jQuery, and I'd like to thank
the collective jQuery community for making such a positive impact
on web development.
Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to the
eBook version at www.PacktPub.comand as a print book customer, you
are entitled to a discount on the eBook copy. Get in touch with us
at [email protected] for more details.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you
full access to all Packt books and video courses, as well as industry-
leading tools to help you plan your personal development and
advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the
heart of our editorial process. To help us improve, please leave us an
honest review on this book's Amazon page at https://www.amazon.com/
dp/1785882988.
If you'd like to join our team of regular reviewers, you can e-mail us
at [email protected]. We award our regular reviewers with
free eBooks and videos in exchange for their valuable feedback. Help
us be relentless in improving our products!
Dedication
For Melissa, Jason, Simon, and Kevin. Thanks for all the
love and support.
Table of Contents
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started
What jQuery does?
Why jQuery works well?
What's new in jQuery 3?
Browser support
Deferred objects
Asynchronous document-ready
All the rest
Making our first jQuery-powered web page
Downloading jQuery
Setting up jQuery in an HTML document
Adding our jQuery code
Finding the poem text
Injecting the new class
Executing the code
The finished product
Plain JavaScript versus jQuery
Using development tools
Chrome Developer Tools
Summary
2. Selecting Elements
Understanding the DOM
Using the $() function
CSS selectors
Styling list-item levels
Selector specificity
Attribute selectors
Styling links
Custom selectors
Styling alternate rows
Finding elements based on textual content
Form selectors
DOM traversal methods
Styling specific cells
Chaining
Iterating over jQuery objects
Accessing DOM elements
Summary
Further reading
Exercises
3. Handling Events
Performing tasks on page load
Timing of code execution
Handling multiple scripts on one page
Passing an argument to the document ready callback
Handling simple events
A simple style switcher
Enabling the other buttons
Making use of event handler context
Consolidating code using event context
Shorthand events
Showing and hiding page elements
Event propagation
The journey of an event
Side effects of event bubbling
Altering the journey - the event object
Event targets
Stopping event propagation
Preventing default actions
Delegating events
Using built-in event delegation capabilities
Removing an event handler
Giving namespaces to event handlers
Rebinding events
Simulating user interaction
Reacting to keyboard events
Summary
Further reading
Exercises
4. Styling and Animating
Modifying CSS with inline properties
Setting computed style property values
Using vendor-specific style properties
Hiding and showing elements
Effects and duration
Speeding in
Fading in and fading out
Sliding up and sliding down
Toggling visibility
Creating custom animations
Building effects by hand
Animating multiple properties at once
Positioning with CSS
Simultaneous versus queued effects
Working with a single set of elements
Bypassing the queue
Queuing effects manually
Working with multiple sets of elements
Queuing with callbacks
In a nutshell
Summary
Further reading
Exercises
5. Manipulating the DOM
Manipulating attributes and properties
Non-class attributes
Value callbacks
Data attributes
DOM element properties
The value of form controls
DOM tree manipulation
The $() function revisited
Creating new elements
Inserting new elements
Moving elements
Wrapping elements
Explicit iteration
Using inverted insertion methods
Copying elements
Cloning for pull quotes
Content getter and setter methods
DOM manipulation methods in a nutshell
Summary
Further reading
Exercises
6. Sending Data with Ajax
Loading data on demand
Appending HTML
Working with JavaScript objects
Retrieving JSON
Using global jQuery functions
Executing a script
Loading an XML document
Choosing a data format
Passing data to the server
Performing a GET request
Serializing a form
Keeping an eye on the request
Error handling
Ajax and events
Deferreds and promises
Performing Ajax calls on page load
Using fetch()
Summary
Further reading
Exercises
7. Using Plugins
Using a plugin
Downloading and referencing the Cycle plugin
Calling a plugin method
Specifying plugin method parameters
Modifying parameter defaults
Other types of plugins
Custom selectors
Global function plugins
The jQuery UI plugin library
Effects
Color animations
Class animations
Advanced easing
Additional effects
Interaction components
Widgets
jQuery UI ThemeRoller
The jQuery Mobile plugin library
HTML5 custom data attributes
Mobile navigation
Delivering multiple pages in one document
Interactive elements
List views
Toolbar buttons
Advanced features
Summary
Exercises
8. Developing Plugins
Using the dollar ($) alias in plugins
Adding new global functions
Adding multiple functions
Extending the global jQuery object
Isolating functions within namespaces
Adding jQuery object methods
Object method context
Implicit iteration
Enabling method chaining
Providing flexible method parameters
Options objects
Default parameter values
Callback functions
Customizable defaults
Creating plugins with the jQuery UI widget factory
Creating a widget
Destroying widgets
Enabling and disabling widgets
Accepting widget options
Adding methods
Triggering widget events
Plugin design recommendations
Distributing a plugin
Summary
Exercises
9. Advanced Selectors and Traversing
Selecting and traversing revisited
Dynamic table filtering
Striping table rows
Combining filtering and striping
More selector and traversal methods
Customizing and optimizing selectors
Writing a custom selector plugin
Selector performance
Sizzle selector implementation
Testing selector speed
DOM traversal under the hood
jQuery traversal properties
The DOM element stack
Writing a DOM traversal method plugin
DOM traversal performance
Improving performance using chaining
Improving performance with caching
Summary
Further reading
Exercises
10. Advanced Events
Revisiting events
Loading additional pages of data
Displaying data on hover
Event delegation
Using jQuery's delegation capabilities
Choosing a delegation scope
Delegating early
Defining custom events
Infinite scrolling
Custom event parameters
Throttling events
Other ways to perform throttling
Extending events
More about special events
Summary
Further reading
Exercises
11. Advanced Effects
Animation revisited
Observing and interrupting animations
Determining the animation state
Halting a running animation
Caution when halting animations
Using global effect properties
Disabling all effects
Defining effect durations
Multi-property easing
Using deferred objects
Animation promises
Taking fine-grained control of animations
Summary
Further reading
Exercises
12. Advanced DOM Manipulation
Sorting table rows
Sorting tables on the server
Sorting tables using Ajax
Sorting tables within the browser
Moving and inserting elements revisited
Adding links around existing text
Sorting simple JavaScript arrays
Sorting DOM elements
Storing data alongside DOM elements
Performing additional pre-computation
Storing non-string data
Alternating sort directions
Using HTML5 custom data attributes
Sorting and building rows with JSON
Modifying the JSON object
Rebuilding content on demand
Revisiting attribute manipulation
Using shorthand element creation syntax
DOM manipulation hooks
Writing a CSS hook
Summary
Further reading
Exercises
13. Advanced Ajax
Implementing progressive enhancement with Ajax
Harvesting JSONP data
Handling Ajax errors
Using the jqXHR object
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Ajax promises
Caching responses
Throttling Ajax requests
Extending Ajax capabilities
Data type converters
Adding Ajax prefilters
Defining alternate transports
Summary
Further reading
Exercises
Appnedix A – Testing JavaScript with QUnit
Downloading QUnit
Setting up the document
Organizing tests
Adding and running tests
Asynchronous testing
Other types of tests
Practical considerations
Further reading
Summary
Appendix B – Quick Reference
Selector expressions
Simple CSS
Position among siblings
Position among matched elements
Attributes
Forms
Miscellaneous selectors
DOM traversal methods
Filtering
Descendants
Siblings
Ancestors
Collection manipulation
Working with selected elements
Event methods
Binding
Shorthand binding
Triggering
Shorthand triggering
Utility
Effect methods
Predefined effects
Custom animations
Queue manipulation
DOM manipulation methods
Attributes and properties
Content
CSS
Dimensions
Insertion
Replacement
Removal
Copying
Data
Ajax methods
Issuing requests
Request monitoring
Configuration
Utilities
Deferred objects
Object creation
Methods of deferred objects
Methods of promise objects
Miscellaneous properties and functions
Properties of the jQuery object
Arrays and objects
Object introspection
Other
Preface
I started using jQuery in 2007, and I'm still using it today. Granted, a
lot has happened between now and then: new JavaScript libraries,
more consistency across browsers, and enhancements to JavaScript
itself. The one thing that hasn't changed in 10 years is the
expressiveness and conciseness of jQuery. Even with all the new
hotness out there today, jQuery remains the go-to tool of choice for
getting work done quickly, and efficiently.
This book has a long history behind it, and it remains intact in its
fifth edition. It has been a successful book because it is straight to
the point and easy to follow. I've done my best to preserve what has
worked so well for this book. My goal is to modernize learning
jQuery for the current web-development landscape.
What this book covers
Chapter 1,Getting Started, gets your feet wet with the jQuery
JavaScript library. The chapter begins with a description of jQuery
and what it can do for you. It then walks you through downloading
and setting up the library as well as writing your first script.
Title: Saknarth
Language: English
The Master Astrologer leaned on the railing and stared at it. The
huge mirror, kept in condition by the attendants, gleamed brilliantly.
The great instrument at the end of the hall near the window, the
Eastern sky visible. The sun rose in sight of that window, and the
Morning Star. From where the telescope stood, it should be possible
to train it on the planet.
The Master Astrologer became excited; he glanced around hurriedly
for fear someone might have witnessed. Then carefully he took in all
details of the lay of the room, turned and walked out.
It was dark. A chill wind from the deserts swept through the deserted
streets of the Martian capital. A period of deepest silence when even
the eternal thumping of the canal pumps died down to a dull distant
hum. In the dim stretches of the hour before dawn the city was at its
quietest. On the street corners a few sleepy guards leaned against
walls and closed their single great eyes in rest for a moment.
Down a side street in the darkest shadows slipped a figure. Dark
cloaked, treading upon cushioned toes, it crept from building to
building, keeping as much as possible in the recesses of arches of
the little carved balconies Martian buildings are wont to have. Finally
the figure came to a halt in a doorway. It stood for a moment looking
around to make sure of the place and then producing a long thin
instrument, picked the lock and rolled aside the door.
Saknarth stepped softly inside the dark hallway, rolled the door shut.
He listened a moment, then assured by silence tip-toed forward up
the incline that he knew lay to one side of the hall. Up he climbed.
Reaching a floor, he turned quickly and groped for the next incline,
reached it and ascended again. Soon he came to where there were
no more floors, and pushing aside a trap door, stepped out on the
roof.
It was not so dark up here. The dim lights of the two tiny moons
added to the lights of the myriad stars to cast a misty white glow
upon objects.
The astrologer tip-toed silently across the roof onto an adjoining one.
On he progressed to come finally to the great wall of a building
looming up above. Set in this wall was a large window about fifteen
feet above his head.
Saknarth groped under his cloak, drew out a long thin rope. To the
end of this he fastened a small, strong double hook making an
effective grappling iron.
He stepped back, whirled it around his head and tossed it upwards.
It struck the wall just below the sill, bounded back. He waited and
listened; no one had heard. Again he tossed the rope; and this time
the hook caught in the carved decorations of the window sill.
Saknarth pulled; the rope held. He whispered a short prayer and
grasping high on the rope raised his feet off the ground. Immediately
he swung inward to touch the wall with his feet. Then, slowly and
laboriously, climbed up the rope.
Reaching the sill, Saknarth threw a leg over and lay quiet for a
moment. Still safe. He drew out his lock-picking instrument and
easily opened the window enough to permit him to creep through
and drop silently on the other side.
The long hall was dark and quiet. No one had heard him. He looked
up. There next to him loomed the great telescope.
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.