开发者

How to expand particular parent in Jquery

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 p开发者_运维百科arent 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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜