I’ve got a div called nav, in which some other divs are placed. When I click on one, I want it to change the colour to orange, which is fine – using this.
I’d like the others to remain black when they aren’t clicked though.
Can not be used with this?
$('.nav div').click(function() {
$(this).css('color', 'orange');
$('.nav div:not(this)').css('color', 'black');
});
You can use the
.not()method instead of the selector:Or you could use the
.siblings()method