Exercise 10.8

This is Exercise 10.8, lecture on modifying DOM with Javascript, used in the course IDATA2301 Web technologies at NTNU, campus Aalesund.

Go back to exercise list.

Purpose

The purpose of the exercise is to learn how you can access and modify element classes in Javascript.

Instructions

  1. Create a page with one paragraph of text.
  2. Add a CSS block which sets a yellow background and font to Courier New for all items with class yellow.
  3. Add two buttons A and B to the page.
  4. Button A should have a text "Add". When user clicks on it, class yellow is added to the text paragraph (and hence it should get a yellow background).
  5. Button B should have a text "Remove". A click on it removes the yellow class from the paragraph.

Solution

You can find a solution in here.