Home>

Why don't I see the characters I typed when there are no errors?
I would appreciate it if you could teach me.

Code let button = document.querySelector ('.btn');
button.addEventListener ('click', function () {
    let input = document.querySelector ('.input');
    input.value =='';
    if (input.value =='') {
    let stop_list = document.querySelector ('.stop-list');
    let li_stop = document.createElement ('li');
    li_stop.classList.add ('list');
    li_stop.textContent = input;
    console.log (li_stop);
    let div_delete = document.createElement ('div');
    div_delete.classList.add ('delete')
    div_delete ='Delete';
    div_delete.addEventListener ('click', function () {
        let hantei = confirm ('Are you sure I want to delete?');
        this.parentElement.remove ();

li_stop.appendChild (div_delete);
  stop_list.appendChild (li);
  document.querySelector ('.input'). value ='';
      })
    }
})
Code<body>
<header>
   STOP DOING LIST 
 <form>
     <input type = "text" placeholder = "Add your list here">
<Input type = "button" value = "Add">
 </form>
           <script src ='todo.js'></script>
</header>
</body>
  • Answer # 1

    I think the code indentation should be properly arranged.

    let button = document.querySelector ('.btn');
    button.addEventListener ('click', function () {
        let input = document.querySelector ('.input');
        input.value =='';
        if (input.value =='') {
            let stop_list = document.querySelector ('.stop-list');
            let li_stop = document.createElement ('li');
            li_stop.classList.add ('list');
            li_stop.textContent = input;
            console.log (li_stop);
            let div_delete = document.createElement ('div');
            div_delete.classList.add ('delete')
            div_delete ='Delete';
            div_delete.addEventListener ('click', function () {
                let hantei = confirm ('Are you sure you want to delete?');
                this.parentElement.remove ();
                li_stop.appendChild (div_delete);
                stop_list.appendChild (li);
                document.querySelector ('.input'). value ='';
            })
        }
    })

    On top of that

    let input = document.querySelector ('.input');
    input.value =='';// This is not an assignment but an evaluation formula, is that okay?
     let div_delete = document.createElement ('div');
    div_delete.classList.add ('delete')
    div_delete ='Delete';
    div_delete.addEventListener ('click', function () {// I'm trying to add an event to an element that isn't on the screen just by creating an element, is that okay?

  • Answer # 2

    if (input.value =='') {

    So it looks like nothing is done only when the input value is empty.
    Also, I can't find the stop-list class in the if

Related articles