Get parent <li> item with jQuery

html, javascript, jquery, jquery-selectors, treeview

Solution

var parentModule = $('this')             //the selector of your span
    .parents('li:eq(1)')                 //get the next li parent, not the direct li
    .children('.rightclickarea:first')   //get the first element, which would be the span
    .attr('id')                          //get the span id

Problem

I am trying to get the parent `<li>` when I click on a specific `<li>` item. http://jsfiddle.net/doonot/GjbZk/ So let's say I click on `submodule 1`, I get the clicked ID with `$(this).attr('id');` How can I now get the ID of the parent `<li>` which is in this case `module 1`? Please note that my tree is quite big, so it has to be flexible. Thanks a lot, much appreciate your answer.

Original source