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

164
Views
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 answers
Answer question

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