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

187
Views
Hide input tag made by js after click icon

i made an input tag using js after click an icon. I want to hide input tag after i click icon again.. here is my js code

const icon = document.querySelector('.menu li:nth-child(1)');

icon.addEventListener("click", function () {
    const input = document.createElement('input');
    input.setAttribute('type', 'search');
    input.placeholder = 'search';
    const ul = document.querySelector('.menu');
    const li = document.querySelector('.menu li:nth-child(1)');
    ul.insertBefore(input, li);

});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can go two ways...

  1. Create the search input element as a permanent DOM element and hide/unhide it as necessary.

  2. If you want to keep the element dynamic, try coding it like this...

     icon.addEventListener("click", function () {
     const search_input_elem = document.getElementById("search_input");
     if (search_input_elem){
         search_input_elem.remove();
     } else {
         const input = document.createElement('input');
         input.setAttribute('type', 'search');
         input.placeholder = 'search';
         const ul = document.querySelector('.menu');
         const li = document.querySelector('.menu li:nth-child(1)');
         ul.insertBefore(input, li);
     }
    

    });

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!