user949239
user949239

Reputation: 1

getting a tab name instead of the index

I have an application that updates databases based on the tabs name been clicked on. I need to be able to get the tab's name using the index number.

<div id="id_tabs" class="tabs" > </div>
<ul class="d_tabs">
  <li id="id_tab_home"><a href="#tab_home">Home</div>     </a></li>
  <li id="id_tab_first"><a href="#tab_first">First</div></a></li>
  <li id="id_tab_second"><a href="#tab_second">Second</div></a></li>
</ul>

Upvotes: 0

Views: 2060

Answers (2)

Senad Meškin
Senad Meškin

Reputation: 13756

First of all your HTML code is not valid, </div> is closed before </a> fix that

code for getting name is like this in click method

var name = $('#' + $(this).attr('id') + ' a:first-child').html();

and that is it

Upvotes: 0

Blazemonger
Blazemonger

Reputation: 92893

$('ul.d_tabs li').eq(idx).attr("id") will return the ID (string) for whatever idx (number) you feed it.

Upvotes: 3

Related Questions