Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
how can i make the input field to be empty after i click a button?

i tried using userinput.value = '' at the end of function but the input is still not empty. here is the code that i've tried

let input = document.querySelector('input')
let list = document.querySelector('ul')
let button = document.querySelector('button')

button.addEventListener('click', addtodo)

function addtodo() {
  let userinput = input.value
  let li = document.createElement('li')
  li.innerText = userinput
  list.appendChild(li)
  // console.log(this)
  console.log(userinput)
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can reset the value of the input with input.value = ""

let input = document.querySelector('input')
let list = document.querySelector('ul')
let button = document.querySelector('button')

button.addEventListener('click', addtodo)

function addtodo() {
  let userinput = input.value
  let li = document.createElement('li')
  li.innerText = userinput
  list.appendChild(li)
  input.value = ""
}
<input type="text" />
<ul></ul>
<button>button</button>

about 4 years ago · Juan Pablo Isaza Report

0

Hope this Helps :)

    let input = document.querySelector('input')
    let list = document.querySelector('ul')
    let button = document.querySelector('button')

    button.addEventListener('click', addtodo)

    function addtodo() {
      let userinput = input.value
      let li = document.createElement('li')
      li.innerText = userinput
      list.appendChild(li)
      // console.log(this)
      input.value = ''
      console.log(userinput)
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!