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

143
Views
How do I filter an array by display type if display type is set by bootstrap?

I am trying to filter an array of portfolio cards so that I can see which items are displayed or not.

let pfCard = document.getElementsByClassName("PortfolioCard")

const visibleCards = [...document.getElementsByClassName("PortfolioCard")].filter(x => x.style.display != "none");
console.log(visibleCards.length);

The displayed cards are having the display set to none by a bootstrap class when the media query is met. The code I have been trying to run still grabs all the elements in the array no matter the display type. There are 8 elements in the array and 2 are set to display: none; currently.

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

0

Because the element's display property is set by the CSS file, you'll need to get the computed style using window.getComputedStyle:

let pfCard = document.getElementsByClassName("PortfolioCard")

const visibleCards = [...document.getElementsByClassName("PortfolioCard")].filter((x) => {
  return window.getComputedStyle(x).display != "none"
});
console.log(visibleCards.length);
.PortfolioCard {
  width: 100px;
  height: 100px;
  background: red;
  margin: 10px;
}

.PortfolioCard:nth-child(3) {
  display: none;
}
<div class="PortfolioCard"></div>
<div class="PortfolioCard"></div>
<div class="PortfolioCard"></div>

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!