0

I'm using the jQuery tabs API, and I need to add a list of Add Buttons to a tab's content. What is the proper way to do this? When I try the following, nothing happens when I click the button:

  $( function() {

            $.createElement = function(name)
            {
                return $('<'+name+' />');
            };

        function addTab(objId){

            // .... do stuff

          for(i = 0; i < objIds.length; i++)

            var b = $.createElement('button');
            b.attr('title', 'adds a ' + label + ' tab');
            b.attr('id', 'add_tab_'+createId());

            // AddTab button: just opens the dialog
            b.button().on( "click", function() {
                addTab(objId[i]);
            });

            b.text(label);
            buttonPanel.append(b);
            tabs.append(buttonPanel);

          } // for each objId

         } // addTab

});

1 Answer 1

1

Try this:

$(document).ready(function() {
            var i = 0;
            function addTab(id) {
                $('#tab').append("<button title='add as a label_"+id+"' id='add_tab_"+id+"'>"+id+"</button>")
            }
            $('#btn_add').on( "click", function() {
                i++;
                addTab(i);
            });
        });
Sign up to request clarification or add additional context in comments.

2 Comments

It's inside the addTab(objId) method. I don't know if I can extract it. I will update the code to show this.
I will try adding them to a queue, then looping the queue outside the addTab() method...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.