You may want to check out the Toggle function. It might eliminate the need for the IF. Maybe even the toggleClass() method? http://www.jquery.com/api
$(".doSetSelect").toggle(function(){ $(this).parents(".def_set").addClass("selected"); },function(){ $(this).parents(".def_set").removeClass("selected"); }); Of course you don't need to use the css class, but it's sometimes easier that way, especially if you have several rules on it. I didnt follow the part you said about display block, but you can do the following: $(this).parents(".def_set:visible").addClass("selected"); :visible means "Only find the ones that are not not display:none." Glen On 8/7/07, dug <[EMAIL PROTECTED]> wrote: > > > Dear all, > > I've been faffing with this thing all morning. The more I faff, the > closer I get to using getElementById. The following should toggle the > background colour of a submit button's parent (a containing 'span' tag > pair set to display:block) > > I am obviously missing something very simple. > > $(".doSetSelect").click(function(event) { > > if ($(this).parents(".def_set").css("backgroundColor") == > "rgb(238,238,238)") > { $(this).parents(".def_set").css({backgroundColor: > "rgb(255,255,255)"}) } > else > { $(this).parents(".def_set").css({backgroundColor: > "rgb(238,238,238)"}) } > > return false; > }); > > In expectation of kicking myself ;-) > > All the best, > Dug > >