I would set the background color of an element by onclick javascript function. My code is:
function changeBg( el ) {
if( $( el ).css( "background-color" ) === "rgb(255,255,0)" ) {
$( el ).css( "background-color", "red" );
}
else {
$( el ).css( "background-color", "rgb(255,255,0)" );
}
}
This code works for change the default background color to yellow (rgb(255, 255,0)) but it doesn't work from yellow to red. The first condition is always skipped
$( el ).css( "background-color" ) === "rgb(255, 255, 0)"