javascript - Show the correct tabs when Bootstrap Modal is called -


i have 3 buttons in homepage , modal 3 tabs. want fire correct tab when respective buttons clicked. how should go it?

for example: want show "careers" tab if careers button clicked. likewise, same contact & partners too.

<div class="row"> <div class="col-xs-4"><a data-toggle="modal" data-target="#mymodal"><span class="btn btn-primary">contact</span></a></div> <div class="col-xs-4"><a data-toggle="modal" data-target="#mymodal"><span class="btn btn-primary">careers</span></a></div> <div class="col-xs-4"><a data-toggle="modal" data-target="#mymodal"><span class="btn btn-primary">partners</span></a></div> </div>  <!-- modal--> <div id="mymodal" class="modal fade" role="dialog">   <div class="modal-dialog">     <div class="modal-content">       <div class="modal-header">         <a href="" class="pull-right" data-dismiss="modal">close</a>         <ul class="nav nav-tabs">             <li class="active"><a data-toggle="tab" href="#contact">contact</a></li>             <li><a data-toggle="tab" href="#careers">careers</a></li>             <li><a data-toggle="tab" href="#partners">partners</a></li>         </ul>       </div>       <div class="modal-body">          <div class="tab-content">             <div id="contact" class="tab-pane fade in active">                 <h3>contact form</h3>             </div>             <div id="careers" class="tab-pane fade">                 <h3>careers form</h3>             </div>             <div id="partners" class="tab-pane fade">                 <h3>partners form</h3>             </div>         </div>       </div>     </div>   </div> </div> 

demo

just add data-target-tab="#contact" correct tab name on each of buttons. , on show.bs.modal (bootstrap modal events), open correct tab (bootstrap tab methods).

$('#mymodal').on('show.bs.modal', function (event) {   var button = $(event.relatedtarget)    $("a[href='"+button.data('target-tab')+"']").tab('show'); }) 

here working fiddle


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -