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

159
Views
Border color value return by window.getComputedStyle

Given the code below,

const handleClick=()=>{
console.log(window.getComputedStyle(document.getElementById("transparent")).borderColor);
  console.log(window.getComputedStyle(document.getElementById("red")).borderColor);
}
<div id='transparent' style='border: 2px solid transparent'/>
<div id='red' style='border: 2px solid red'/>
 


<button className="App" onclick="handleClick()">
  something
</button>

it output rgba(0, 0, 0, 0) for transparent color rgb(255, 0, 0) for red color.

Will it always output in such a format for transparent and red color (e.g, not #ff0000 or red)? The reason is that I am going to do a conditional check for transparent color in my code using the following:

if (window.getComputedStyle(document.getElementById("red")).borderColor == 'rgba(0, 0, 0, 0)'){
   //do something...
}

Will it be a good practice or there are better way to do that?

about 4 years ago · Juan Pablo Isaza
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!