...">
    Geek asks and answers

    Jquery accessor id vs class?

    at this link: http://jqueryui.com/demos/tabs/ , when we look at the "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 I want to know how to implement this with a class instead of id,
    given that this part of the code will be used several times, which can be loaded by ajax,
    at different times.

    +3
    jquery class jquery-ui-tabs
    asdf_enel_hak May 11 '11 at 12:55
    source share
    5 answers

    for adding tabs dynamically, there is an add method that will automatically show you the tab controls, which allows you to reuse the tab creation code again.

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

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

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

    +4
    btx 11 '11 13:09

    jQuery ui div, . , , html .

    .

    <script>
       $(function() {
         $( "#tabs" ).tabs();
         $( "#tabs2" ).tabs();
       });
       </script>
    
        <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>
    
        <div id="tabs2">
            <ul>
                <li><a href="#tabs2-1">...</a></li>
                <li><a href="#tabs2-2">...</a></li>
                <li><a href="#tabs2-3">...</a></li>
            </ul>
            <div id="tabs2-1">...</div>
            <div id="tabs2-2">...</div>
            <div id="tabs2-3">...</div>
        </div>
    
    +1
    Till 11 '11 13:00

    .

    , .

    ( ), ? , "".

    (css), id.

    +1
    Kraz 11 '11 13:02

    , , jquery ui, .

    div jqueryui, .

    The link href attribute in the tab itself is encoded to search for specific div content. therefore href = "# tab-1" will always show a div with the id "# tab-1".

    Here's how it works. If you want to use the class instead, you need to change / extend the functionality of the jquery ui tab in the jqueryui library. Or you can write your own jQuery tab plugin.

    +1
    Patrick May 11 '11 at 13:03
    source share

    You can use addClass method

    $('#some_ul_id li').addClass(function(i, curr) {
      return "item-" + i;
    });
    
    +1
    Pawel zubrycki May 11 '11 at 13:38
    source share

    More articles:

    • How to get the last three values โ€‹โ€‹of Arraylist - java
    • Need advice on a link to a managed COM server (EXE) from a client application - c #
    • https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1811979/can-managementscope-be-used-to-send-wbem-queries-to-linux-macos-clients-from-windows-c&usg=ALkJrhi9l6Sm7ecrGt1S9tWGIcWWJ4lsnw
    • Signs of Spanish accent in presentation of form - php
    • How to list linux process from C # .net client? - c #
    • Is using Amazon s3 as a database (for sorting) for a PHP application the wrong solution? - javascript
    • Cannot send cURL to PHP - php
    • Widget 4x2 - appwidget-provider minWidth and minHeight for all permissions - android
    • ARM v7 BKPT instruction does not work correctly on Linux 2.6.35 - linux
    • IQueryable ะดะปั IQueryable - linq

    All Articles

    Geek-Ask | 2020