javascript - Open close buttons function bootstrap -


i using bootstrap collapse hide , show content on page , change bit. here example bootply.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">    <div class="container">    <div class="row">      <div class="col-md-6 col-lg-6">        <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#first">first</button>        <div id="first" class="collapse">          lorem ipsum dolor sit amet, consectetur adipisicing elit,          sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam,          quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.        </div>      </div>       <div class="col-md-6 col-lg-6">        <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#second">second</button>        <div id="second" class="collapse">          lorem ipsum dolor sit amet, consectetur adipisicing elit,          sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam,          quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.        </div>      </div>     </div>   </div>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

let's first 1 open , second closed. when click on second , opens first 1 close (and other way around).

is possible javascript/jquery? still learning javascript/jquery , have little knowledge, appreciated.

bootstrap accordion without panels

the accordion example requires use of panel component. however, similar behavior can achieved blocks.

you can cook simple jquery script using following ingredients:

  1. show.bs.collapse event:

    this event fires when show instance method called.

  2. .collapse('hide') method:

    hides collapsible element.

  3. .collapse.in class:

    • .collapse hides content
    • .collapse.in shows content

please check result: bootply

$('.collapse').on('show.bs.collapse', function () {    $('.collapse.in').collapse('hide');  })
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">    <div class="container">    <div class="row">      <div class="col-md-6 col-lg-6">        <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#first">first</button>        <div id="first" class="collapse">          lorem ipsum dolor sit amet, consectetur adipisicing elit,          sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam,          quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.        </div>      </div>       <div class="col-md-6 col-lg-6">        <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#second">second</button>        <div id="second" class="collapse">          lorem ipsum dolor sit amet, consectetur adipisicing elit,          sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam,          quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.        </div>      </div>     </div>   </div>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -