SheTech
  • SheTech JS bootcamp
  • Level 1 - awesome tasks
    • Introduction to Awesome Tasks
    • Step 1: HTML
    • Step 2: playing with the DOM
    • Step 3: add a new task
    • Step 4: dynamic list of tasks
    • Step 5: adding new items
    • Step 6: removing items
    • Step 7: add some style
    • Step 8: marking items as done
    • Step 9: saving items in the localstorage
    • Step 10: adding filters and bulk actions
    • Step 11: add counters
    • From Awesome Task to the next big thing!
  • Level 2 - timeline
    • Live Timeline
    • Step 1: basic HTML page
    • Step 2: add util library
    • Step 3: show all posts
    • Step 4: add form
    • Step 5: collect form data
    • Step 6: create a new post
    • Step 7: validating posts
    • Step 8: refactoring
    • Step 9: refresh button
    • Step 10: auto refresh
  • Code Editors
  • Useful resources
  • API Reference
  • Glossary
Powered by GitBook
On this page

Was this helpful?

  1. Level 1 - awesome tasks

Step 3: add a new task

The first thing we are going to do is to take control of the task list; we will use JavaScript for adding a new task.

Before </body>, let’s add this:

3.1 — The <script> tag

<script>
  let listElement = document.querySelector('#task-list');
  let element = document.createElement('li');
  element.innerHTML = 'Disco dance';
  listElement.appendChild(element);
</script>

If we reload the page now, we will see a new task pop up in our list and it comes straight from JavaScript!

What we just did:

  • We used the document.querySelector() DOM API to access our #task-list element

  • We modified its innerHTML property by adding some more HTML: our new task item

PreviousStep 2: playing with the DOMNextStep 4: dynamic list of tasks

Last updated 3 years ago

Was this helpful?