0

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?

3
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by Taywin
1

Assuming that the field argument is a HTML object. Try $(field).css instead? If it is still not working, you may need to pass in the field name instead of the object but still need the $() thing.

Edited by Taywin

0

I ended up going about it an entirely different way. While he (Taywin) did not solve it perse, he had a good point.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.