I am trying to check for the background of an element, here is my code. But it doesn't work:
I tried two ways, here is the first:
function changeColor(field) {
if(field.css('background-color','#ffb100')) {
field.css('background-color','white');
}
else {
field.css('background-color','ffb100');
}
}
here is the second:
function changeColor(field) {
if(field.css('background-color') === '#ffb100') {
field.css('background-color','white');
}
else {
field.css('background-color','ffb100');
}
}
But neither worked! Any suggestions?
EDIT: This is my latest code, but it still is not working:
function changeColor(field) {
if(field.css('background-color') == 'rgb(255, 255, 255)') {
field.css('background-color','ffb100');
}
else {
field.css('background-color','white');
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…