Reputation: 2586
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
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
Reputation: 1141
tabs.click(function(e) {
e.prevetDefault();
alert($(this).attr('id'));
});
Upvotes: 0