On my html page, I have multiple menus. When a line item is clicked, I want to get the id attribute of the parent anchor tag from the menu where the selection originates. My html and jquery code is below.
//HTML
<ul id="menuA">
<li>
<a href="#" id="ageGroup" class="age">Age Group</a>
<ul>
<li name="ageGroup"><a href="#">18-21</a></li>
<li name="ageGroup"><a href="#">21-30</a></li>
<li name="ageGroup"><a href="#">30-40</a></li>
<li name="ageGroup"><a href="#">40-50</a></li>
<li name="ageGroup"><a href="#">50-60</a></li>
<li name="ageGroup"><a href="#">60-70</a></li>
<li name="ageGroup"><a href="#">70-80</a></li>
<li name="ageGroup"><a href="#">80-90</a></li>
<li name="ageGroup"><a href="#">90-100</a></li>
</ul>
</li>
</ul>
//JQUERY
$(function(){
$('#menuA').menu({
select: function(event, ui){
var choice = ui.item.text(); //get text of menu selection
//here is where I want to get the id attribute of the anchor tag. What I have isn't working. id is coming up undefined.
var id = ui.item.parents('a').attr('id');
}
});