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

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

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 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