Gene9y Gene9y - 2 months ago 6
jQuery Question

Get an id of the active a link

I am trying to get the id of the activated link of a element.

<div class="tabs">
<a class="title active" id="tab-1"></a>
<a class="title" id="tab-2"></a>
<a class="title" id="tab-3"></a>
</div>
<div id="close"></div>

<script>
$('#close').click(function() {
alert($('.tabs').find('a:active').attr('id'));
}
<\scripts>


The alert returns 'undefined'. What's not right with this?

Answer

Try like this

 alert($('.active').attr('id'));