Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename jQuery UI tab with jQuery

I have 3 tabs :

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Tab1</a></li>
        <li><a href="#tabs-2">Tab2</a></li>
        <li><a href="#tabs-3">Tab3</a></li>
    </ul>
    <div id="tabs-1"></div>
    <div id="tabs-2"></div>
    <div id="tabs-3"></div>
</div>

with this jQuery

<script type="text/javascript">
    $(document).ready(function () {
        var $tabs = $("#tabs").tabs({
            select: function (e, ui) {
            }
        });
    });
</script>

I'd like when I do some operation on the first and the third tab, the label of second tab change the name from "Tab2" to "Other text"

I tried several way found on Google but any work.

Thanks,

like image 697
Kris-I Avatar asked May 29 '11 21:05

Kris-I


3 Answers

You could just run the following code and it will change the text for the second tab link.

$('#tabs ul:first li:eq(1) a').text("Other text");

Example (click button in 3rd tab)

like image 122
Niklas Avatar answered Nov 15 '22 03:11

Niklas


Alternatively, for anyone that wants to change the text of a specific tab, "#tabs-2" in this case:

$('#tabs [aria-controls=tabs-2] a span').text("New Label")

Note that this is dependent on the current formatting of the jquery-ui tabs and may need to be tweaked if the template changes in future versions.

like image 39
Digicrat Avatar answered Nov 15 '22 04:11

Digicrat


I found another solution if you don't want to use the indices in case they are dynamic.

$('#tabs a[href=#idoftab]').text("New Title");
like image 21
EricWC Avatar answered Nov 15 '22 05:11

EricWC