Gene9y
Gene9y

Reputation: 859

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?

Upvotes: 2

Views: 330

Answers (3)

user5633496
user5633496

Reputation:

Please update this with your jquery

    $(document).ready(function(){
     $('#close').click(function() {
    alert($(this).parent().find('a.active').attr('id'));
     alert($('.tabs').find('a.active').attr('id'));
     }
    )

       });

If it solve your problems accept it

Upvotes: 1

Ankit Lad
Ankit Lad

Reputation: 41

Try This

alert($(".tabs a").find('a:active').attr('id'));

Upvotes: 1

Bharat
Bharat

Reputation: 2464

Try like this

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

Upvotes: 1

Related Questions