Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery accessor id vs class?

at this link: http://jqueryui.com/demos/tabs/ when we look "view source", we have:

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

so what I want to know, how to implement this with class instead of id,
considering this portion of code will be used multiple times that may be loaded ajax,
in different times.

like image 708
asdf_enel_hak Avatar asked Apr 25 '26 19:04

asdf_enel_hak


1 Answers

for dynamically adding tabs, there is an add method that will auto-name your tab controls for you, thus letting you re-use your tab creation code repeatedly.

When a tab is added to the page, it fires the add event, as shown in the tabs doc page:

var $tabs = $('#example').tabs({
    add: function(event, ui) {
        $tabs.tabs('select', '#' + ui.panel.id);
    }
});

from http://jqueryui.com/demos/tabs/#default

like image 56
btx Avatar answered Apr 27 '26 07:04

btx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!