I know that this question was answered multiple times here on stackoverflow, but i just can't get it to work on my problem.
What i want to do is, when a <label> is clicked, check for the labels class and change all matching elements to backgroundColor : #000000
Here is my code:
$(function() {
$('label').click(function(){
var group = this.className ;
$('label .'+group).css({
'backgroundColor' : '#000000'
}) ;
}) ;
});
Unfortunately, this just does nothing. It even throws no error. Where is my fault?
Solution
I had to remove the whitespace in the selector:
$('label.'+group)
group?$('label .'+group)labelcontains more than one class name, which could cause problems for your selector. We need more information.$('label.a_2')means "labels with the classa_2",$('label .a_2')means "any element with the classa_2that's a descendant of alabel".