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

147
Views
Clearing input field text after button click

Am trying to get the value from input and display it, once I input another value, the previous value is still returned,once I click the add button but I dont want it to. How can I solve this is Javascript here is my code.

const addEvent = document.querySelector('.add');
const eventUserInput = document.querySelector('.input2');
const parentEl = document.querySelector('.event-list');

eventUserInput.addEventListener('keyup', (user_input)=>{
    let userValue = user_input.target.value;
    // console.log(userValue);
    addEvent.addEventListener('click', ()=>{
        const storeElement = document.createElement('p');
        const storeElementText = storeElement.innerHTML = userValue;
        console.log(storeElement);
        parentEl.appendChild(storeElement);
        eventUserInput.value = '';
        // document.getElementById('input').value = '';
        // parentEl.push(storeElement)

    })
})
 <div class="list">
        <label for="input"></label>
        <input type="text" id="input" class="input2" placeholder="enter activity">
        <i class="ri-add-fill add">btn</i>

        <div class="event-list">
        
        </div>
    </div>

about 4 years ago · Santiago Gelvez
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!