Menu
CoddyTech

Project: The Clear Button

Part of the JSON APIs section of Coddy's Django journey. Lesson 17 of 19.

The endpoint works; now the home page gets a button for it. The new app.js is ready, and its last line wires it up:

document.getElementById("clear-done").addEventListener("click", clearDone);

addEventListener("click", clearDone) runs clearDone on every click of that element. clearDone posts to your endpoint, writes "Cleared " + result.deleted + " done tasks." into the element with the id message, and calls showSummary() and showTasks() again so the page shows the new state. The script decides the ids; your page must match them.

challenge icon

Challenge

Medium

Read the new app.js, then add to the home page:

  • The button the script listens to, saying Clear done tasks.
  • The element its message goes into.

Press Run and click the button: the message says how many tasks went, and Call the bank leaves the list.

Try it yourself

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Task tracker</title>
</head>
<body>
    <h1>Task tracker</h1>
    <p id="summary"></p>
    <ul id="task-list"></ul>
    <script src="{% static 'tasks/app.js' %}"></script>
</body>
</html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in JSON APIs

Practice on your own: Django playground