Get ID of a clicked parent ID

Get ID of a clicked parent ID

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> var ddmenuitem = 0; function jsddm_open() { // When "help-menu" being click, I will toggle drop down menu. ddmenuitem = $(this).find('ul').eq(0).toggle(); } function jsddm_close(evt) { // When everywhere in the document except "help-menu" being clicked, I will close the drop down menu. // How I can check everywhere in the document except "help-menu"? var id = $(this).parent().attr("id"); // Why undefined when I click on Help? alert(id); if (ddmenuitem) ddmenuitem.hide(); } $(document).ready(function() { $('#jsddm > li').bind('click', jsddm_open); $(this).bind('click', jsddm_close); }); </script> <ul id="jsddm"> <li><a href="#">Home</a></li> <li><a href="#" id="help-menu"><u>Help</u><small>xx</small></a> <ul> <li><a href="#">menu item 1</a></li> <li><a href="#">menu item 2</a></li> </ul> </li> </ul>




When I click on "Help", I expect to get "help-menu". However, I get "undefined".

May I know what's wrong with  $(this).parent().attr("id");