Using jQuery to find ID of containing element -


<li id="someid">     <div id="div1">text</div>     <div id="div2">text x 2</div>     <div id="div3">text x 3</div>         <span>             <div>                 <ul>                     <li class="menuitem">menu item</li>                 </ul>             </div>         </span> </li> 

in short, i'm trying find id "someid" when class "menuitem" clicked. code below doesn't seem cutting it.

$('.menuitem').click(function(){alert($(this).closest('li').attr('id'));}); 

instead of .closest('li'). use .parents('li'). (note plural)

it mentioned @ closest() documentation ..


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -