Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
Why some operations do not apply to an element with two CSS classes?

I have two input elements and a button as follows:

<input class="close-acc-usr opt-in" type="text" name="closeAccUsr" />
<input class="close-acc-pin opt-in" type="number" name="closeAccPin" />
<button class="opt-btn close-btn">→</button>

In js I want to by clicking on the button, both input element contents become clear, so I write this line of code in the button event handler function:

document.querySelector('.opt-in').value = '';

but it does not work!! in fact if I write above code for '.close-acc-pin' and '.close-acc-usr' class names instead of .opt-in it works! but why with '.opt-in' it does not work?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try to select all inputs with querySelectorAll :

const btn = document.querySelector('.opt-btn')
btn.addEventListener('click', function() {
  const inputs = document.querySelectorAll('.opt-in');
  inputs.forEach(input => input.value = '')
})
<input class="close-acc-usr opt-in" type="text" name="closeAccUsr" />
<input class="close-acc-pin opt-in" type="number" name="closeAccPin" />
<button class="opt-btn close-btn">→</button>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of using two classes for that input why not change that opt-in class into an id like this:

<input id="opt-in" class="close-acc-usr" type="text" name="closeAccUsr" />
→

Then in your JS this:

document.querySelector('#opt-in').value = '';

or better still this

 document.getElementById('opt-in').value = '';
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda