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

159
Vistas
What does (document.querySelector('.inner-button')) ? document.querySelector('.inner-button').classList.remove('inner-button') : ''; do in my code

I have a section of code that adds a class to a button if clicked and takes the class off if another button is clicked and adds that class specifically to that button.

specificButtons.forEach(button => {
    button.addEventListener('click', ()=> {
        const innerDiv = button.childNodes[1];

        (document.querySelector('.inner-button')) ? document.querySelector('.inner-button').classList.remove('inner-button') : '';
        innerDiv.classList.add('inner-button');
    });

    button.addEventListener('click', ()=> {
        pledgeOffers.forEach(offer => {
            console.log(offer);
        });
    });
});

I specifically took this line of code from a website and added my own classes and it works great with my project, however i'm not sure what it does and would like to understand what it's doing and why it's doing it. I tried many different If statements to get the code to work and nothing worked until I found this line. Could someone please help explain.

(document.querySelector('.inner-button')) ? document.querySelector('.inner-button').classList.remove('inner-button') : '';

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

0

exp ? exp1 : exp2; means if exp is true it will jump to exp1, otherwise exp2.
You can get more informantion from Conditional (ternary) operator

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