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

158
Views
¿Qué hace (document.querySelector('.inner-button')) ? document.querySelector('.inner-button').classList.remove('inner-button') : ''; hacer en mi código

Tengo una sección de código que agrega una clase a un botón si se hace clic y quita la clase si se hace clic en otro botón y agrega esa clase específicamente a ese botón.

 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); }); }); });

Tomé específicamente esta línea de código de un sitio web y agregué mis propias clases y funciona muy bien con mi proyecto, sin embargo, no estoy seguro de lo que hace y me gustaría entender qué está haciendo y por qué lo está haciendo. Probé muchas declaraciones If diferentes para que el código funcionara y nada funcionó hasta que encontré esta línea. ¿Podría alguien ayudarme a explicar?

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

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

0

exp ? exp1 : exp2; significa que si exp es verdadero, saltará a exp1 , de lo contrario, exp2 .
Puede obtener más información del operador condicional (ternario)

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!