Creating a modal pop up

A modal is a pop up within a web page that overlays over all other content and focuses the reader's attention. A modal is often opened based on user interaction, such as clicking a button. This recipe will show you how to create a simple modal that is opened at the pressing of a button and can be closed from within the modal.

Getting ready

Once again, create recipe-10.html, recipe-10.css, and recipe-10.js before you start this recipe, ensuring that the latest version of jQuery is available in the same directory as these files.

How to do it…

Perform the following steps to create the modal pop up:

  1. Add the following HTML to recipe-10.html to create a basic web page and the code that constructs the modal pop up:
    <!DOCTYPE html> <html> ...

Get jQuery 2.0 Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.