Get ID of a clicked parent ID

Posted by Yan Cheng CHEOK on Stack Overflow See other posts from Stack Overflow or by Yan Cheng CHEOK
Published on 2010-03-14T06:17:55Z Indexed on 2010/03/14 6:25 UTC
Read the original article Hit count: 194

Filed under:

I try using evt.parent.attr("id") inside jsddm_close, but it doesn't work.

<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"?
    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>

© Stack Overflow or respective owner

Related posts about jQuery