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

227
Views
How do you check if a css class is present on an element?

i have this piece of code where i wanna check if a css class is present,if so then want to remove that specific class.

var el = document.querySelector('.main-content');

const promo = 'projectPromoActivateMobile';
const transaction = 'projectTransactionActivate';
const newsletter = 'projectNewsletterActivate';
const landingPage = 'projectLandingPageActivate ';

const classLists = [promo,transaction,newsletter,landingPage]


let check = el.classList.contains(promo || transaction ||newsletter || landingPage);

console.log(check);

this does the work and check but can not seem to get the name of the class,which needs to be removed.

how would you check if that specific css class is present in the element?

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

0

promo || transaction || newsletter || landingPage will resolve to promo, since all values are strings of non-zero length (therefore truthy). All following values will be ignored.

Therefore, this code :

let check = el.classList.contains(promo || transaction ||newsletter || landingPage);

is exactly the same as this :

let check = el.classList.contains(promo);

Instead, you want to use something like this:

const classLists = ["promo","transaction","newsletter","landingPage"];
let check = el.classList.some(class => classLists.includes(class));
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!