Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
jQuery 2.0 Development Cookbook
jQuery 2.0 Development Cookbook

jQuery 2.0 Development Cookbook: As a web developer, you can benefit greatly from this book - whatever your skill level. Learn how to build dynamic modern websites using jQuery. Packed with recipes, it will quickly take you from beginner to expert.

eBook
$19.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

jQuery 2.0 Development Cookbook

Chapter 2. Interacting with the User by Making Use of jQuery Events

In this chapter, we will cover:

  • Detecting button clicks
  • Detecting element clicks
  • Detecting change
  • Updating content based on user input
  • Detecting key press events on inputs
  • Restricting input character length
  • Changing page elements on mouse hover
  • Triggering events manually
  • Preventing event triggers
  • Creating a custom event

Introduction

This chapter looks at how you can make use of jQuery's many events to allow your interface to respond to different user interactions, such as button clicks, and also how jQuery events can help you with form validation.

Detecting button clicks

Clicking on website elements is a primary user interaction; therefore, detecting these clicks is a very fundamental aspect in creating interactive web applications. There are various ways in which jQuery developers can listen for certain button presses within their web page.

Getting ready

Using your favorite text editor or IDE, create a blank HTML page named recipe-1.html in an easily accessible location.

How to do it…

Create two buttons with click event handlers by performing the following steps:

  1. Add the following HTML code to recipe-1.html. Be sure to change the location of the jQuery library in the JavaScript file, pointing it to where the latest version of jQuery is downloaded on your computer.
    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js"></script>
        <script>
    
        </script>
    </head>
    <body>
        <button class="button1...

Detecting element clicks

Having the ability to detect if a user has clicked on elements other than buttons can provide additional flexibility to your web application. You can attach click events to any HTML elements, just as we did with the buttons in the previous recipe.

Getting ready

To work through this recipe, we are first going to need a blank HTML page named recipe-2.html, the same as in the other recipes. Remember that you need to have the latest version of jQuery downloaded and easily accessible on your computer so that it can be included in recipe-2.html.

How to do it…

To understand how you can detect user clicks on elements other than buttons, perform the following steps:

  1. Add the following HTML to the recipe-2.html page you have just created. This HTML creates a very basic web page with an input, an anchor, and a division element.
    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js&quot...

Detecting change

While creating dynamic and interactive websites and web applications, it is useful to know when a user has changed something on the page, such as the value of a selected input, a text input, or any other element that has a modifiable value.

Getting ready

Once more, create a new blank HTML document named recipe-3.html. Ensure that you have the latest version of jQuery downloaded, which can be included into this HTML file.

How to do it…

To learn how to attach change event handlers to various element types, perform the following steps:

  1. Add the following HTML code to the HTML document you have just created, and update the reference to the jQuery library in order to ensure that the latest version of jQuery is being included into the page:
    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js"></script>
        <script>
    
        </script>
    </head>
    <body>
    &lt...

Updating content based on user input

jQuery allows developers to easily process user input and then update the page to reflect this input. The previous recipes of this chapter have looked at detecting changes on input values and clicks on various page elements. This recipe will help you to create a web page that will update a header element based on the title that has been selected from a drop-down menu.

Getting ready

Create a blank HTML document named recipe-4.html, with the latest version of the jQuery library downloaded and ready for use.

How to do it…

Using techniques similar to those you have learned in the previous recipes, perform the following steps to make changes to the DOM based on user interaction:

  1. Add the following HTML code to recipe-4.html, which you have just created; don't forget to update the reference to the jQuery library. This HTML creates a basic HTML web page with a drop-down menu element, allowing the user to choose a number of titles. There is also a header...

Introduction


This chapter looks at how you can make use of jQuery's many events to allow your interface to respond to different user interactions, such as button clicks, and also how jQuery events can help you with form validation.

Detecting button clicks


Clicking on website elements is a primary user interaction; therefore, detecting these clicks is a very fundamental aspect in creating interactive web applications. There are various ways in which jQuery developers can listen for certain button presses within their web page.

Getting ready

Using your favorite text editor or IDE, create a blank HTML page named recipe-1.html in an easily accessible location.

How to do it…

Create two buttons with click event handlers by performing the following steps:

  1. Add the following HTML code to recipe-1.html. Be sure to change the location of the jQuery library in the JavaScript file, pointing it to where the latest version of jQuery is downloaded on your computer.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js"></script>
        <script>
    
        </script>
    </head>
    <body>
        <button class="button1">Button 1</button...

Detecting element clicks


Having the ability to detect if a user has clicked on elements other than buttons can provide additional flexibility to your web application. You can attach click events to any HTML elements, just as we did with the buttons in the previous recipe.

Getting ready

To work through this recipe, we are first going to need a blank HTML page named recipe-2.html, the same as in the other recipes. Remember that you need to have the latest version of jQuery downloaded and easily accessible on your computer so that it can be included in recipe-2.html.

How to do it…

To understand how you can detect user clicks on elements other than buttons, perform the following steps:

  1. Add the following HTML to the recipe-2.html page you have just created. This HTML creates a very basic web page with an input, an anchor, and a division element.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js"></script...

Detecting change


While creating dynamic and interactive websites and web applications, it is useful to know when a user has changed something on the page, such as the value of a selected input, a text input, or any other element that has a modifiable value.

Getting ready

Once more, create a new blank HTML document named recipe-3.html. Ensure that you have the latest version of jQuery downloaded, which can be included into this HTML file.

How to do it…

To learn how to attach change event handlers to various element types, perform the following steps:

  1. Add the following HTML code to the HTML document you have just created, and update the reference to the jQuery library in order to ensure that the latest version of jQuery is being included into the page:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js"></script>
        <script>
    
        </script>
    </head>
    <body>
    <select id="names...

Updating content based on user input


jQuery allows developers to easily process user input and then update the page to reflect this input. The previous recipes of this chapter have looked at detecting changes on input values and clicks on various page elements. This recipe will help you to create a web page that will update a header element based on the title that has been selected from a drop-down menu.

Getting ready

Create a blank HTML document named recipe-4.html, with the latest version of the jQuery library downloaded and ready for use.

How to do it…

Using techniques similar to those you have learned in the previous recipes, perform the following steps to make changes to the DOM based on user interaction:

  1. Add the following HTML code to recipe-4.html, which you have just created; don't forget to update the reference to the jQuery library. This HTML creates a basic HTML web page with a drop-down menu element, allowing the user to choose a number of titles. There is also a header element that...

Detecting key press events on inputs


jQuery provides three event functions that allow the jQuery developer to determine what key a user is pressing, and when and how the user is pressing it. The .keyup() function is an event handler that can be attached to an input and will be fired once the pressed key has been fully released; likewise, .keydown()will be fired once the key has been fully pressed. The third available event handler is .keypress(), which is fired instantly when a key is pressed.

These methods allow the developer to provide powerful client-side validation or to provide the user with simple features such as triggering a form submission when the Enter key is pressed.

Getting ready

Create a blank HTML file named recipe-5.html which we can use for this recipe.

How to do it…

Use a variety of event handlers to detect user key press events by performing the following steps:

  1. Add the following HTML code to the web page you have just created. Update the reference to the jQuery library to ensure...

Left arrow icon Right arrow icon

Description

Taking a recipe-based approach, this book presents numerous practical examples that you can use directly in your applications. The book covers the essential issues you will face while developing your web applications and gives you solutions to them. The recipes in this book are written in a manner that rapidly takes you from beginner to expert level. This book is for web developers of all skill levels. Although some knowledge of JavaScript, HTML, and CSS is required, this Cookbook will teach jQuery newcomers all the basics required to move on to the more complex examples of this book, which will benefit the more seasoned jQuery developer. If you want to learn how to create modern website features quickly, using best practice techniques, then this book is for you.

What you will learn

  • Use jQuery and CSS to create more complete animations
  • Construct a mobile website and web app with jQuery Mobile
  • Create robust web forms for collecting user data with validation and user feedback
  • Build powerful user interface elements to provide an intuitive experience for your users
  • Add style to your interfaces with effects and basic animations
  • Utilize jQuery and AJAX to load content into pages without the need for refreshing

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 21, 2014
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781783280902
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Feb 21, 2014
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781783280902
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
jQuery 2.0 Development Cookbook
$48.99
jQuery for Designers Beginner's Guide Second Edition
$43.99
Learning jQuery - Fourth Edition
$43.99
Total $ 136.97 Stars icon

Table of Contents

11 Chapters
1. Document Object Model Manipulation Chevron down icon Chevron up icon
2. Interacting with the User by Making Use of jQuery Events Chevron down icon Chevron up icon
3. Loading and Manipulating Dynamic Content with AJAX and JSON Chevron down icon Chevron up icon
4. Adding Attractive Visuals with jQuery Effects Chevron down icon Chevron up icon
5. Form Handling Chevron down icon Chevron up icon
6. User Interface Chevron down icon Chevron up icon
7. User Interface Animation Chevron down icon Chevron up icon
8. Understanding Plugin Development Chevron down icon Chevron up icon
9. jQuery UI Chevron down icon Chevron up icon
10. Working with jQuery Mobile Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(12 Ratings)
5 star 33.3%
4 star 50%
3 star 16.7%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




J. Facey Mar 19, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
First I must say really liked the examples that are used throughout the book. They are well documented and intended with an easy to follow style for learning jQuery.The first few chapters provide a great introduction to jQuery. Concepts such as traversing the Document Object Model and handling basic DOM events such as click and hover are expertly explained. The later chapters of the book cover sections on jQuery UI, jQuery Mobile and making jQuery Plugins by extending the platform.Chapter 8 is a great guide to on extending jQuery to create plugins. One of which I have started on my own site as a jQuery plugin toolkit for small effects.For my job I use a lot of dialog overlays and progress bars that utilize jQuery UI and found the sections describing this (Ch 9) to be very useful.All in all I have to say this is one the best books I have read for jQuery development and recommend this to new users and those who may have come from other JavaScript libraries (YUI, Sencha, Dojo, Prototype) to ramp up their jQuery skills.
Amazon Verified review Amazon
Hernán Apr 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Covers all aspects of jQuery and gives many practical examples for anyone wanting to start taking your first steps. It really covers a practical, concise and comprehensive all subjects.The first chapters give a theoretical overview of DOM and later touch topics such as AJAX, JSON and form handling. It is also very interesting chapter on plugins and development, covering very detailed implementation.Really a very good book that should have everyone who wants to start and begin to develop this technology. Highly recommended.
Amazon Verified review Amazon
Fallen Cloud Jun 10, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I think there are two kinds of programming books. Ones that dive heavily into theory, often at the expense of practical examples, and ones that show you examples with little explanation. I don't know what most people were expecting, but cookbooks are usually just examples of how to apply a specific language in various situations.To that end, I think this book is very good. I read one other book that was steeped in theory and was having trouble figuring out how all the pieces fit together. This book was exactly what I needed. Not only did it start from basic jQuery and work it's way up, it also provided enough examples for me to really feel comfortable writing my own code.I don't know if this book would be as useful to an experienced developer, but since I'm still gaining experience, it was perfect for me.
Amazon Verified review Amazon
Keith Stephens Jun 06, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good book to learn Angular
Amazon Verified review Amazon
Justyn Roberts Mar 09, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Some super examples here - Just what I needed, no fluff - straight to the point - obviously written by someone who has lots of real world experience. Recommended.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.