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

188
Views
Why my secont event listerner won't work after the first one

I have a profile page and there is an edit button. When I click the edit button you can edit the information on the page.

The thing is the second event listener won't work when I click the button done which is appeared after clicking the edit button, nothing changes.

```const editButton = document.querySelector('.edit-btn');
const doneButton = document.querySelector(".done-btn");
const textBox = document.querySelector('.txt-box');
const textArea = document.querySelector('.description');
const pwbox = document.querySelector('.pw-box');
const dateBox = document.querySelector(".date-joined");```
editButton.addEventListener('click', e => {
  textBox.removeAttribute('readonly');
  textArea.removeAttribute('readonly');
  textBox.style.borderBottom = '1px gray solid';
  pwbox.style.display = "flex";
  doneButton.style.display = "block";
  editButton.style.display = 'none';
  dateBox.style.display = "none";
});

doneButton.addEventListener('click', e => {
  textBox.setAttribute("readonly");
  textBox.style.removeProperty('background color');
  textBox.style.removeProperty('border-bottom');
  pwbox.style.display = "none";
  doneButton.style.display = "none";
  editButton.style.display = 'block';
  dateBox.style.display = "flex";
});
<div class="infobox">
  <input type="text" name="uname" class="uname txt-box" value="<?php echo $usersName ?>" readonly autocomplete="off">
  <input type="text" name="email" class='email' value="<?php echo $usersEmail ?>" readonly>
  <div class="pw-box">
    <label for="password">Password</label>
    <input type="password" name="password" class="password">
    <label for="confirmPassword">Confirm Password</label>
    <input type="password" name="conf-password" class="conf-password">
  </div>
  <div class=" date-joined">
    <small>Date Joined</small>
    <div>01/01/01</div>
  </div>

</div>
<div class="description-box">

  <textarea name="description" class="description" cols="30" rows="10" placeholder="Let me describe you!" readonly></textarea>
  <button class='edit-btn'>Edit</button>
  <button class="done-btn">Done</button>

</div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

The problem is the .setAttribute in my js file, it need 2 parameters instead of one. Thanks for helping out.

about 4 years ago · Juan Pablo Isaza Report

0

You should set the readonly attribute to true

textBox.setAttribute("readonly", true);
about 4 years ago · Juan Pablo Isaza Report

0

Instead of using an event listener, you could probably use this and call a function when you click the button <input type="button" class="button" onclick="editFunction()" value="Edit" />

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!