Have you tried using context
?
$('#cboxWrapper', context).css('backgroundColor', bg);
It makes sure your cssCSS is ran with the new markup Or checked.
Did you check that your selector actually works ?
console.log($('#cboxWrapper')); // Then check your console