javascript - How to check in jQuery if a Bootstrap tab isn't clicked? -
i have tabs in bootstrap:
<ul class="nav nav-tabs" role="tablist"> <li>tab1</li> <li>tab2</li> <li>tab3</li> <li>tab4</li> <li>tab5</li> </ul> <p id="message"></p>
how can make when no tab clicked message 'please select tab' shown?
i have made <p id="message"></p>
underneath tabs, need insert message when no tab clicked , remove message when tab clicked i'm not sure how check.
for bootstrap tabs need content containers. in case put message div tab-content
div:
<!-- tab panes --> <div class="tab-content"> <div role="tabpanel" class="tab-pane" id="home">...</div> <div role="tabpanel" class="tab-pane" id="profile">...</div> <div role="tabpanel" class="tab-pane" id="messages">...</div> <div role="tabpanel" class="tab-pane" id="settings">...</div> <p id="message">please select tab</p> </div>
... , make hide in case selected simple css rule:
.tab-pane.active ~ #message { display: none; }
.tab-pane.active ~ #message { display: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <link data-require="bootstrap-css@*" data-semver="3.3.1" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" /> <ul class="nav nav-tabs" role="tablist"> <li role="presentation"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">home</a></li> <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">profile</a></li> <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">messages</a></li> </ul> <!-- tab panes --> <div class="tab-content"> <div role="tabpanel" class="tab-pane" id="home">home</div> <div role="tabpanel" class="tab-pane" id="profile">profile</div> <div role="tabpanel" class="tab-pane" id="messages">messages</div> <p id="message">please select tab</p> </div>
Comments
Post a Comment