views:

38

answers:

2

Hi I have a menu made using jquery.I want that when i click on particular parent only child under that parent shud expand all other child under other parent shud get hide.
I have got parent id so based on that i can expand a particular parent.

My code is as follows.

<script>
$(document).ready(function(){
  var msg1;
  var msg14;
var msg = false;
alert((document.getElementById(''P17_LOCATION_ID'')).value);
alert(msg14);
$(''.dropdown_menu'').click(function(event) {
msg = !msg;
if (msg)'
$(this).parent(''.parent_menu'').find(''.child_menu'').slideDown("slow");
  else 
$(''.child_menu'').hide();
return false;
 });
' });
</script>

Here - $(this).parent(''.parent_menu'').find(''.child_menu'').slideDown("slow"); is responsible for sliding down of child menu for parents but currently all the child menus are expanding which i want to stop and when i click on some parent then child under that parent only shud be displayed so how i can pass the id to this statement above. Kindly suggest some solution

+2  A: 

$(expr).parent(sel) returns all parents of expr that match sel. you wan't $(this).closest('.parent_menu')

just somebody
Hi,Thanks for the reply.I got what u meant but what i want is when user select any child items my page gets refreshed and hence all the submenu gets expanded so i want that after $(document).ready(function(){I will be need to add something which will only expand a particular submenu whose parentid is passed which is accessible here.Kindly suggest some solution as it is very urgent.
Bhavesh
A: 

Alternatively, you could also use only the first element in the collection returned by parent():

$(this).parent('.parent_menu').eq(0).find('.child_menu').slideDown('slow');

However, I agree that closest() is more elegant, and it basically does the same thing. Hope my post clarifies things for you, anyway.

Tom Bartel
hihtp.p;htp.p('<script>');htp.p(' $(document).ready(function(){');htp.p(' var msg14 = ($(''#P17_LOCATION_ID'').val());');htp.p(' alert(msg14);');htp.p(' $(''dd:not(:first)'').hide();');htp.p(' $(''dt a'').click(function(){');htp.p(' $(''dd:visible'').slideUp("slow");');htp.p(' $(this).parent().next().slideDown("slow");');htp.p(' return false;');htp.p(' });');htp.p(' });');htp.p('</script>');here i am able to see the first parent on page refresh say i want toview the last parent id expanded when page refreshes so is there any metho instead of :first which i can use here
Bhavesh