Reputation: 10936
I am creating jquery tabs dynamically. I want to associate the the id to each tab.
$(function() {
var index = 0;
$("#addTab").live('click', function() {
index++;
var title = 'Tab..... ' + index;
var url = '#fragment-' + index;
addTab(url, title, index);
$('li.ui-state-default').attr("id",index);
});
This code successfully assigns the id. But when I create a new tab. It assigns the id to whole class. I didn't want to do this. I just want to assign the unique id to each class
JS Fiddle
Upvotes: 1
Views: 11816
Reputation: 87073
$('li.ui-state-default:last').attr("id",index).attr('id');
Upvotes: 4
Reputation: 48793
$('li.ui-state-default').each( function(){
$(this).attr("id",index++);
});
By the way, it's bad practice to use numbers as DOM Element's id, use something like ("item-"+index)
as id
attribute.
Upvotes: 4