CS396: Spring 2021

Intro to Web Development

CS396: Spring 2021

Assignments > Lab 4. Event Handlers and the DOM

Due on Fri, 04/23 @ 11:59PM. 5 Points.

Download Tutorial Files

Get Oriented with the Files

In this week’s lab, you will be manipulating the DOM using various event handlers. Before you begin, some notes:

After inspecting the starter code, please complete the following tasks:

1. Implement the Thumbnail Click Event Handler

In the js/index.js file, create and attach an event handler (function) to the onclick event of each thumbnail (div element with a class of .image). When the thumbnail is clicked, the event handler should update the backgroundImage of the .featured-image element with the image of the thumbnail that was just clicked (see video below).

destinationElement.style.backgroundImage = sourceElement.style.backgroundImage;

2. Implement the Next and Previous Click Event Handlers

When you’re done with Step 1, implement the “next” and “previous” click event handlers:

Tips

Consider using a global variable to track the index position of the image that is currently being displayed. You can detect this by accessing the data-index attribute of the .image. See hints/index-hint-2.js if you want a hint.

When the .featured-image is clicked, invoke the same function that is invoked when .next is clicked.

Demo

What to turn in

Please zip your entire lab04 folder and submit to Canvas.