0

What I'm trying to do is give my user 4 options (simple links). If the click one of these, a div below is shown based on their selection. The issue I'm having is figuring out how to hide the div below if another top link is clicked. Right now I'm able to show all 4 sub-divs at the same time, where it should hide the currently visible one, then show the new one.

Any help?

Thanks!

2 Answers2

0

This assumes all children of container_id are divs:

function show_item( container_id, item_id ) {
allItems = $(container_id).getElementsBySelector( 'div' );
$A(allItems).each(Element.hide);
$(item_id).show();
}

  • Thanks! Bear with me, as I'm new to JS - so if my 4 sub divs are id="a1", id="a2", id="a3", and id="a4" - do I need 4 functions based on the code above but switching out container_id with the appropriate id I want to show?? –  Aug 28 '09 at 23:18
  • To show a1 do: show_item( 'top', 'a2' );
    –  Aug 28 '09 at 23:25
0
$$('.sub-selection').each(Element.hide);
$('#selected_element').show();
Duncan Beevers
  • 1,830
  • 11
  • 17
  • 1
    think you may have added some jquery in the second code sample, should be: $('selected_element').show(); first one could also be rewritten as: $$('.sub-selection').invoke("hide"); – robjmills Sep 07 '09 at 11:57