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

343
Views
JS addEventListener for "input" change made by code

I am writing a JS event listener to hide button if the entered value in a text field is true:

const item = document.getElementById("my-field");
item.addEventListener("input", function (evt) {
  if (item.value == "true") {
    document
      .getElementById("my-button")
      .setAttribute("style", "display: none;");
  }
});

This works fine if I manually add this value, but I have another JS function (running as a part of chrome extension) that does it. The eventListener doesn't work then. Any idea how can I make this work when a JS code is inputting the value?

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

0

Try replacing input with change, like this:

item.addEventListener('change', function (evt) {
                        if (item.value == 'true') {
                            document.getElementById("my-button").setAttribute("style", "display: none;");
                        }
                        });

This may solve the problem.

about 4 years ago · Juan Pablo Isaza Report

0

I suspect you have access to change the extension you're dealing with? If so, you probably want to use this method (just reverse the order here. You're going from extension to index.html): https://stackoverflow.com/a/11431812/3011559

If not, you may have to resort to polling the input quickly and checking for changes. There might be some hacky ways to detect changes (you might want to look into MutationObserver) with events when the changes are changed programmatically. However, considering the changes are by an extension, the contexts are isolated. It makes it tricky by design.

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!