javascript - slideUp() all the elements but not the selected ones -


all want is:

  • there 7 numbers , 7 divs, linked each other (nr 0 it's in relationship div 0)
  • when 1 of numbers clicked, should collapse other divs not selected
  • it can selected more @ 1 time

to sum up, basically, page has labels numbers , 7 divs displayed default (the divs), when 1 or more of them chosen clicking on numbers, page should display chosen divs.

this i've been trying do:

for(var = 0; <= 6; i++) {                  if(i != (floors[i])) {                 $("#lvl" + floors[i]).slideup();             }         } 

more code: http://jsfiddle.net/lsjg4/

i corrected few things in code. here below working code , link in jsfiddle.

there data type mismatch(comparing string , int). when matching whether exists in floors array, code checking floors[i] whereas can position in floors.

var floors = []; $(".nr").click(function () {         var state = $(this).data('state');         state = !state;          if (state) {             $(this).css("background-color", "#1b7664");             $(this).css("border-color", "#236959");             floors.push(parseint($(this).text()));             console.log(floors);              for(var = 0; <= 6; i++) {                   ret = $.inarray(i, floors);                 if(ret==-1) {                     $("#lvl" + i).slideup();                 }                 else {                      $("#lvl" + i).slidedown();                 }             }          } else {             $(this).css("background-color", "#02c099");             $(this).css("border-color", "#13a480");             (var = 0; < floors.length; i++) {                 if (floors[i] == parseint($(this).text()))                     floors.splice(i, 1);             }              for(var = 0; <= 6; i++) {                   ret = $.inarray(i, floors);                 if(ret==-1) {                     $("#lvl" + i).slideup();                 }                 else {                      $("#lvl" + i).slidedown();                 }             }          }         $(this).data('state', state);     }); 

demo here: http://jsfiddle.net/bfe9t/