Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the background-color of an element using jquery

if($(this).css("background-color")==Crimson) 

is this correct ? .css("background-color","white") will change the color, but I don't want to change, I wanna know which color it is.

like image 331
Ali Bassam Avatar asked May 02 '12 09:05

Ali Bassam


1 Answers

it works like this

if ($("#notify-9").css('background-color')=="rgb(220, 20, 60)") alert("matched");

you need to convert name to red, green, blue components, you might use this tool

http://www.yellowpipe.com/yis/tools/hex-to-rgb/color-converter.php

like image 66
Muayyad Alsadi Avatar answered Oct 19 '22 06:10

Muayyad Alsadi