Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

368
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda