jquery selection with .not()
Posted
by
Yako
on Stack Overflow
See other posts from Stack Overflow
or by Yako
Published on 2011-01-10T13:43:06Z
Indexed on
2011/01/10
13:53 UTC
Read the original article
Hit count: 181
jquery-selectors
Hello, I have some troubles with jQuery. I have a set of Divs with .square classes. Only one of them is supposed to have an .active class. This .active class may be activated/de-activated onClick.
Here is my code :
jQuery().ready(function() {
$(".square").not(".active").click(function() {
//initialize
$('.square').removeClass('active');
//activation
$(this).addClass('active');
// some action here...
});
$('.square.active').click(function() {
$(this).removeClass('active');
});
});
My problem is that the first function si called, even if I click on an active .square, as if the selector was not working. In fact, this seems to be due to the addClass('active') line...
Would you have an idea how to fix this ? Thanks
© Stack Overflow or respective owner