Chapter 3. jQuery Events and Functions: Making Things Happen on Your Page

image with no caption

jQuery makes it easy to add action and interactivity to any web page. In this chapter, we’ll look at making your page react when people interact with it. Making your code run in response to user actions takes your website to a whole new level. We’ll also look at building reusable functions so you can write the code once and use it multiple times.

Your jQuery skillz are in demand again

Emily was pleased with the work you did for her Jump for Joy promotion, but she’s met with her accountant and now has a few changes she’d like you to make.

From: Jump for Joy

Subject: RE: Jump for Joy Promotion

Hey,

You did a great job of making the web promotion work! I met with my accountant and crunched some numbers on the success of the promotion.

My accountant suggested some changes to the app that should bring in more sales.

Visitors should still get four options to pick from for the chance to receive a discount. However, now let’s make it the same discount amount each time. My accountant recommends offering 20% off visitors’ purchases before they check out. That should be more enticing for them.

Visitors should only get one chance to find the discount code, which should be in a random square for each visit. If a visitor finds the discount code when she clicks, show it to her on the screen before she proceeds. Otherwise, show her ...

Get Head First jQuery now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.