Skip to main content

JavaScript DOM Attributes — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript DOM Attributes lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Read an attribute

    easy10 min

    Report the href of the link.

  2. 2

    Change an attribute

    easy10 min

    Change the alt text to Updated and report it back.

  3. 3

    Read a data attribute

    easy10 min

    Report the value of data-user-id using dataset.

  4. 4

    Remove an attribute

    easy10 min

    Remove the disabled attribute and report whether it is still there.

  5. 5

    Read a class as a property

    medium10 min

    Report the class of the link using its property, not getAttribute.

Find the bug(5)

  1. 1

    Fix the dot used for a data attribute

    easy8 min

    A data attribute is not a plain property of the element.

  2. 2

    Fix the dashed dataset name

    easy8 min

    dataset uses camel case, not the dashed attribute name.

  3. 3

    Fix setAttribute given one argument

    easy8 min

    setAttribute needs both a name and a value.

  4. 4

    Fix class read as a property name

    easy8 min

    The property is called className, because class is reserved.

  5. 5

    Fix the attribute checked instead of the property

    easy8 min

    A checkbox ticked in code changes the property, not the attribute.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace