Friday, 13 September 2013

jQuery UI removeClass() removes only one match

jQuery UI removeClass() removes only one match

Here's the issue. For some unknown reason, this jQuery UI function only
removes the highlight on the first item with class ".folder", and doesn't
remove it from the rest whenever a different one is clicked. I can't find
anything possibly wrong with the code, yet it doesn't work. The API
documentation states it should affect each element that matches the
pattern.
What gives?
function init_ui(){
// (some other functions omitted)
$('.folder').click(function(){
$('.folder').children().eq(0).removeClass('highlighted');
$(this).children().eq(0).addClass('highlighted');
$(init_ui);
});
}
$(init_ui);
Solution:
Simply remove .eq(0), as that means it will only match the first element
of them all.

No comments:

Post a Comment