Search code examples
jqueryjquery-uitabsjquery-ui-tabsjquery-tabs

add id dynamically to jquery tabs


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

http://jsfiddle.net/gP3YZ/9/


Solution

  • $('li.ui-state-default:last').attr("id",index).attr('id');
    

    DEMO