jquery - Multi-level tab Panel with Bootstrap - adding class .active 2 first-subpanel -
i making multi-level panel page, based on bootstrap. structure fine, sub-panels active when parent panel active too.
my code looks :
<!-- nav tabs n1--> <div class="row"> <div class="col......."> <ul class="nav nav-tabs"> <li class="active"><a href="#1a" data-toggle="tab">a</a></li> <li><a href="#1b" data-toggle="tab">b</a></li> </ul> </div> </div> <!-- /.nav tabs n1--> <!-- content n1 --> <div class="tab-content"> <!-- tab content n1a --> <div class="tab-pane fade active in" id="1a"> <div class="row"> <div class="col...."> <!-- nav tabs n2 --> <div class="row"> <div class="col......."> <ul class="nav nav-tabs"> <li class="active"><a href="#1aa" data-toggle="tab">a1</a></li> <li><a href="#1ab" data-toggle="tab">a2</a></li> </ul> </div> </div> <!-- /.nav tabs n2 --> <!-- content n2 --> <div class="tab-content"> <!-- tab content n21 --> <div class="tab-pane fade active in" id="1aa"> <h1>a1</h1> <p>......</p> </div> <!-- tab content n21 --> <div class="tab-pane fade" id="1ab"> <h1>a2</h1> <p>......</p> </div> </div> <!-- ./content n2 --> </div> </div> <!-- /.tab content n1a --> <!-- tab content n1b --> <div class="tab-pane fade" id="1b"> <div class="row"> <div class="col...."> <!-- nav tabs n2 --> <div class="row"> <div class="col......."> <ul class="nav nav-tabs"> <li class="active"><a href="#1ba" data-toggle="tab">a1</a></li> <li><a href="#1bb" data-toggle="tab">a2</a></li> </ul> </div> </div> <!-- /.nav tabs n2 --> <!-- content n2 --> <div class="tab-content"> <!-- tab content n21 --> <div class="tab-pane fade" id="1ba"> <h1>a1</h1> <p>......</p> </div> <!-- tab content n21 --> <div class="tab-pane fade" id="1bb"> <h1>a2</h1> <p>......</p> </div> </div> <!-- ./content n2 --> </div> </div> <!-- /.tab content n1b --> </div> <!-- ./content n1 -->
i trigger first sub-panel when parent-panel getting active, after clicking on it. tried piece of jquery, not @ not work :
$( "#1b" ).click(function () { ( "#1ba" ).addclass('in active'); });
any idea ?
i have that, perhaps you. if still needs, of course hehehe
function getrootchild(element, childs) { childs.push(element); if (element.next('li.child').length > 0) { getrootchild(element.next('li.child'), childs); } } $("li.list-group-item.root").on('click', function() { var childs = []; getrootchild($(this).next('li.child'), childs); for(idx in childs) { $(childs[idx]).slidetoggle(); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <li class="list-group-item root"> <a href="#"> root item </a> </li> <li class="list-group-item child" style="display: none;"> <a href="#"> child 1 </a> </li> <li class="list-group-item child" style="display: none;"> <a href="#"> child 2 </a> </li>
Comments
Post a Comment