Why does jQuery .css('background-color') return rgba(0,0,0,0) for 'transparent'?

Steve

I have a box here - http://jsfiddle.net/U68p3/2/ - with a transparent background. When I read the background with jQuery's .css('background-color') it returns

               rgba(0, 0, 0, 0) 

which is not very helpful if my code is looking for a match with 'transparent'.

Why is jQuery doing this and is there a way I can make it return 'transparent'?

Thanks.

$(function() {
    var bkgnd = $('#box').css('background-color');
    console.log('background-color is ' + bkgnd);
});
PSL

It is not jquery, the computed value for the color are represented in RGBa (Red, Blue, Green, Alpha - for opacity) and not in as color names (like red, blue, orange, transparent etc) or as hex values. According to the specs transparency is represented as rgb(0, 0, 0).

if the value is translucent, the computed value will be the rgba() corresponding one. If it isn't, it will be the rgb() corresponding one. The transparent keyword maps to rgb(0,0,0).

So instead of looking for this specific value you can add a specific css rule just to include transparency and add that class to the element and use .hasClass or .is of that class to check if the element is transparent.

It seems like different browsers represent it in different ways, IE, FF gives the value as transparency so it is anyways better not to rely on this value representation for any logic.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Transparent color vs rgba(0,0,0,0)

Why does using jquery css background.color remove :hover?

CSS make the background color transparent

Why does a CSS linear-gradient from color1 to color2 render exactly the same as a linear-gradient from color1 to transparent on a color2 background?

why does "float" in css ruin the background color

Background Color to transparent background image in css

CSS - background color set, but still transparent

CSS Inherit for unknown Background Color is Actually Transparent

How to make div background color transparent in CSS

CSS3: Transition of background color to transparent

Background color over transparent PNG image in CSS

How to create transparent background color in html & css

Why does this not return 0

Having a fallback for a transparent background RGBA background in CSS

Why this simple css queries does not change background color

JavaScript - Why does (0 || -0) return -0

Why is my jQuery autocomplete background transparent?

Why does this function return 0

Why does this return a 0 length?

Why does trunc() return 0?

Why does ~0 return -1?

Why does this always return 0?

Why does java return a 0?

Why does this recursion return 0?

Transparent border with background color

Bootstrap transparent panel css background: rgba won't get transparent

CSS - background color around image with some transparent pixels

CSS circle - possible to add a transparent gap between border and background color?

getComputedStyle('background-color') returns transparent, does not inherit ancestor's