Martin Ongtangco
Martin Ongtangco

Reputation:

adding content to a generated tab in JQuery

I added this to my already existing JQuery tab:

function createTab(name) {
    // this will add a tab via the standard method
    $("#tabs").tabs("add", "#fragment-4", name);
    $("#fragment-" + name).css("display", "block");
}

my question is, what is the syntax that allows me to create content inside the newly created tab?

Upvotes: 1

Views: 1674

Answers (2)

David Rice
David Rice

Reputation: 1111

You can also use the template plugin.

<script id="SomeTemplate" type="text/x-jquery-tmpl">
    <h3>A Header with ${some_variable} in it</h3>
        Your content
</script>

Then inside the .add event in tabs, you can append it to the current tab

$tabs = $("#tabs").tabs({
            add: function( event, ui ) {
                var data_to_pass = {some_variable:"data"};
                $("#SomeTemplate").tmpl(data_to_pass).appendTo(ui.panel);
            }
        });

Upvotes: 0

RaYell
RaYell

Reputation: 70414

Just add the contents to the div you are adding:

$('#fragment4').html('Contents added via JS');

Upvotes: 2

Related Questions