d3bug3r
d3bug3r

Reputation: 2586

jQuery - read tab data

I have an HTML snippet as below

 <li class="tab selected" data-tab-id="10">
    <a href="#"></a>
    </li>

  var tabs = $('.tab');
  tabs.click(function(e){
    e.preventDefault();
    alert(data-tab-id value here);
});

When a tab is selected, how can I read the data-tab-id value which I need to pass to AJAX to fetch the right data?

Upvotes: 0

Views: 1034

Answers (2)

bipen
bipen

Reputation: 36531

try this

var tabs = $('.tab');
   tabs.click(function(e){
   e.preventDefault();
   alert($(this).attr('data-tab-id')); //gets data-tab-id  attribute... 10
});

Upvotes: 1

Stefan Fandler
Stefan Fandler

Reputation: 1141

tabs.click(function(e) {
    e.prevetDefault();
    alert($(this).attr('id'));
});

Upvotes: 0

Related Questions