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.
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.
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
Use quotes ""
or ''
:
if($(this).css("background-color")=="Crimson")
"rgb(220, 20, 60)"
if "Crimson"
was set. Try it out: $("<div>").css("background-color","Crimson").appendTo("body").css("background-color")
–
Petulia Use quotes around the color name as:
if( $(this).css("background-color") == "Crimson" )
otherwise it is right.
just use below line
if($(this).css("background-color")=="crimson")
as css("background-color")
attribute result will be in small letters . so if you will compare with capital obviously it will return false. :)
Small trick hope that work
Possible answers in JavaScript is like this:
if(window.getComputedStyle(document.getElementById("notify-9"),null).getPropertyValue("background-color") == "rgb(220, 20, 60)"){
alert("matched!");
}
// rgb(220, 20, 60) is equal to Crimson
© 2022 - 2024 — McMap. All rights reserved.
rgb
orrgba
format older browsers will return the value which was set. – Petulia