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?

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.

What was the solution to your problem?

I believe the $() solves the problem.

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

Oh ok. Sorry about that. But at least you solved your problem and I am glad. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.