tags:

views:

33

answers:

2
+1  A: 

How 'bout:

var id = $("#mainNav li:has(a.selected)").attr("id");

Live example

T.J. Crowder
That returns the id of the link, not its parent.
Alec
@Alec: I realized as I clicked post and fixed it (even before your comment; overlap).
T.J. Crowder
+2  A: 

What you've suggested should work - but I'd simplify it to:

$('#mainNav .selected').parent().attr('id');

(Did you actually try your suggestion?)

Dexter
I did but it was huge!
AnApprentice
I think it should be #mainNav a.selected
AnApprentice
@TheApprentice: Yeah, otherwise anything with the "selected" class inside that div would be fair game.
T.J. Crowder