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

200
Views
Display none, block don't work on mobile. They work second click

I have a problem with select options with display: none, block. On PC it works, there is no problem. But on mobile, it also works, but at the second click and after 1-2 seconds. I don't know what is my mistake. I need when the user clicks yes, the place input must be display: block, price input display: none if the user clicks no the place input must be display: none, price input display: block,

My HTML

     <div class="second-tab">
        <div class="form-group">
           <span class="work-span" id="workspan">Work?</span>
               <select id="work" name="work" class="work">
                   <option value="no" selected>No</option>
                    <option value="yes">Yes</option>
                </select>

         </div>
       <div class="form-group">
           <span id="label-price" class="label-price work-span">Price</span>
            <input type="text" id="price" class="price" />
       </div>
       <div class="form-group">
          <span class="label-place work-span">Place</span>
         <input type="text" id="place" name="place" class="place" />
     </div>
    <div class="form-group">
    <button type="submit">Submit </button>
  </div>
     </div>

My JS

    work.addEventListener("click", (e) => {

            if (e.target.value == "no") {
                priceInput.style.display = "block";
                labelPrice.style.display = "block";
                placeInput.style.display = "none";
                labelPlace.style.display = "none";
            } else if (e.target.value == "yes") {
                priceInput.style.display = "none";
                labelPrice.style.display = "none";
                placeInput.style.display = "block";
                labelPlace.style.display = "block";
            }
        });

My CSS

#label-price {
    display: block;
}

#workspan {
    display: block;
}

.place {
    display: none;
}

.work-span {
    display: none;
}
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Using a change event on a select, you can toggle a class hidding whatever you want.

document.getElementById("select").addEventListener("change", () => {
  document.getElementById("example").classList.toggle("d-none");
})
.d-none{
  display:none;
}
<select id="select">
  <option selected>Show</option>
  <option>Hide</option>
</select>
<div id="example">example</div>

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