1

I have a jquery tab on my page, where each list item contains a hyperlink that should get called whenever someone changes tab (it's a webservice call that fills in values within the tab).

I can accomplish this behaviour when changing tabs, but now I also want the first hyperlink to be called when the .tabs function is called (for initialisation purposes)

How can I do this? Calling this at the end of the page doesn't work:

setTimeout(function() {$('#tabs').tabs('select', 0);}, 0);

Probably because just calling .tabs() already selects the first tab.

My tabs code (js + asp.net):

<div id="tabs" class="tab-panel">
    <ul class="tabs">
        <asp:Repeater ID="rpt" runat="server">                
            <ItemTemplate>
                <li>
                    <asp:HyperLink ID="btnEdit" runat="server" NavigateUrl="myPage.aspx/GetInfo" Text='<%# Eval("Name") %>'></asp:HyperLink>
                    <asp:HiddenField ID="txtId" runat="server" Value='<%# Eval("ID") %>' />
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>
    <div class="tab rounded-bottom rounded-topright">
        <div class="tab-content" id="licRights">
            <input type="text" value="" id="myText">
        </div>
    </div>
</div>

Javascript:

$("#tabs").tabs({
    select: function (event, ui) {
        var Id = $(ui.tab).siblings("input").val();
        var settings = $(this).tabs("option", "ajaxOptions");
        settings.data = $.toJSON({ id: Id });
    },
    ajaxOptions: {
        success: function (response) {
            $("#myText").val(response.d);                        
        }
    }
});
2
  • $("#tabs ul li:gt(0) a").click(); ? Commented Feb 28, 2012 at 10:23
  • @Ohgodwhy this calls a click on every li-a in the list? Commented Feb 28, 2012 at 10:28

1 Answer 1

1

The select event is triggerred when a tab is clicked, not programmatically changed. That is what the documentation says actually.

select
This event is triggered when clicking a tab.

You can see this in action here: only the "show" event is triggerred initially


What you can do is trigger a click on the first tab:

  1. set the defaul selection to " -1 ", so no tab is initially selected (otherwise the programmatic click has no effect)
  2. find the first anchor and trigger a click event

Here's the code:

$("#tabs").tabs({
    selected: -1,
    ...
}).find('.ui-tabs-nav a:first').click()

DEMO

Sign up to request clarification or add additional context in comments.

4 Comments

Makes no difference, nothing happens :-/ Maybe there is a check "if current-selection == target-selection, do nothing"
I've changed the anwser a bit indeed. The plugin does not re-select a tab that is already selected (makes sense).
Thanks! Maybe I should have read the docs on 'selected' too, instead of just the 'how-to' section...
Now you know :o) Glad it helped !

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.