Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
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.

Arrow left icon
Profile Icon Leon Revill
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (12 Ratings)
Paperback Feb 2014 410 pages 1st Edition
eBook
zł39.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial
Arrow left icon
Profile Icon Leon Revill
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (12 Ratings)
Paperback Feb 2014 410 pages 1st Edition
eBook
zł39.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial
eBook
zł39.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781783280896
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 21, 2014
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781783280896
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 zł20 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 zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 553.97
jQuery 2.0 Development Cookbook
zł197.99
jQuery for Designers Beginner's Guide Second Edition
zł177.99
Learning jQuery - Fourth Edition
zł177.99
Total 553.97 Stars icon
Banner background image

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.