I have a problem and I do not know if it is a bug, because jQuery is not capturing the background-color
of the element passed by css()
, I am using a data-color
attribute to configure the element color, in browsers it put the color, follow the image below:
WhenIqueryinjQueryusingthiscommand:$('.btn').css('backgroundColor')
itreturnsmeblankbutwhenIenterthestyle
itworks.
Note:Iamusingthisfunctiontodetectthecolorandcheckifitisalightordarkelement.
constself=$(el)//ElementosletgetBackground=(item)=>{letbackground=item.css('backgroundColor'),alpha=parseFloat(background.split(',')[3],10)if((isNaN(alpha)||alpha>.8)&&background!=='transparent')returnbackgroundif(item.is('body'))returnfalseelsereturngetBackground(item.parent())}letgetLuma=(color)=>{letrgba=color.substring(4,color.length-1).split(','),r=rgba[0],g=rgba[1],b=rgba[2],luma=0.2126*r+0.7152*g+0.0722*breturnluma}//Consultaletcor=getBackground(self),inverse=(getLuma(cor)>183)?'inverse':'',$ripple=$('<divclass="ink' + inverse + '"></div>')
I figured trying to get the data-color
attribute to compare but I do not know how to jQuery
because it returns only the name contained using data()
.