tags:

views:

57

answers:

3

Hi, i have the following (which obviously i cant do!)

function dropBox() {
 $("#reportWrapper a").bind("click", function(){
  $("#reportWrapper a").each(function(i){
   $(this).animate({
      height: '20px'
   }, 1000);        
  });
  $(this).parents("div:eq(0)").animate({
   height: '100px'
  }, 1000);
 });
}

What i want is to open one that is clicked on and close all ones that are open. The box opens box the others dont close. Any help much appreciated. Regards

A: 

If you close them in a way that changes the display property to none, then you can use the jQuery :visible selector to select all others that are open.

cpharmston
Im sorry im new to jQuery (PHP man) could you elaberate some more?
Phil Jackson
can yoiu select an element by is css property? i.e. element.css.height.200px ?
Phil Jackson
A: 

Can enyone see why thisa wouldn't work?

function dropBox() {
 $("#reportWrapper a").bind("click", function(){
  var clicked = $(this);
  $("#reportWrapper a").each(function(){ 
   if( clicked.attr("name") != $(this).attr("name") )
   {
    $(this).animate({
     height: '20px'
    }, 1000);
   }
   else
   {
    clicked.parents("div:eq(0)").animate({
     height: '100px'
    }, 1000);
   }
  });
 });
}

Yet again, the box clicked opens, but the one that is open does not close

function dropBox() {
 $("#reportWrapper a").bind("click", function(){
  var clicked = $(this);
  $("#reportWrapper a").each(function(){ 
   if( clicked.attr("name") !== $(this).attr("name") )
   {
    alert("this: " + $(this).attr("name") + "clicked: " + clicked.attr("name"));
    $(this).animate({
     height: '20px'
    }, 1000);
   }
   else
   {
    clicked.parents("div:eq(0)").animate({
     height: '100px'
    }, 1000);
   }
  });
 });
}

Above, alerts everyone apart from the one thats clicked so im stumped

God damn... just sussed it

Phil Jackson
A: 
function dropBox() {
    $("#reportWrapper a").bind("click", function(){
            var clicked = $(this);
            $("#reportWrapper a").each(function(){  
                    if( clicked.attr("name") !== $(this).attr("name") )
                    {
                            $(this).parents("div:eq(0)").animate({
                                    height: '20px'
                            }, 1000);
                    }
                    else
                    {
                            clicked.parents("div:eq(0)").animate({
                                    height: '100px'
                            }, 1000);
                    }
            });
    });

}

WORKS!

Phil Jackson