JavaScript jquery accordion - onclick opening all accordion jquery accordion onclick event,jquery accordion onclick,jquery accordion onclick

I have created a custom jquery accordion and I am stuck with the code, when I click on accordion title, its opening both of the accordion where it should open the one where I have clicked, following are the codes:

$(document).ready(function() {
    $(".acc-wrap > .acc-head").on("click", function() {
        if ($(this).hasClass('active')) {
            $(this).removeClass("active");
            $(this).siblings('.acc-body').slideUp(200);
            $(".acc-wrap > .acc-head").attr('class', 'acc-head opened');
        } else {
            $(".acc-wrap > .acc-head").attr('class', 'acc-head closed');
            $(this).addClass("active");
            $('.acc-body').slideUp(200);
            $(this).siblings('.acc-body').slideDown(200);
        }
    });
});
.projects-list {
  max-width: 600px;
  margin: 0 auto;
  background: #E0E0E0;
  padding: 15px 0;
  font-family: Roboto;
}
body {
  margin: 0;
  padding: 0;
}
.acc-wrap {
  position: relative;
  width: 100%;
}
.acc-wrap > .acc-head {
  float: left;
  width: 100%;
  display: block;
  background-color: #264796;
  padding: 10px;
  color: #fff;
  font-weight: 600;
  border-bottom: 1px solid #ddd;
  transition: all 0.2s linear;
  position: relative;
}
.acc-wrap > .acc-head.opened {
  position: relative;
}
.acc-wrap > .acc-head.opened:after {
  content: "\f055";
  font-family: fontAwesome;
  position: absolute;
  right: 15px;
}
.acc-wrap > .acc-head.closed {
  position: relative;
}
.acc-wrap > .acc-head.closed:after {
  content: "\f056";
  font-family: fontAwesome;
  position: absolute;
  right: 15px;
}
.acc-body {
  position: relative;
  width: 100%;
  float: left;
  background-color: #fff;
  padding: 10px;
  border-bottom: 1px solid #ddd;
  display: none;
  box-sizing: border-box;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" target='_blank' href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<div class="projects-list">
  <div class="acc-wrap">
    <div class="acc-head opened"> Vestibulum </div>
    <div class="acc-body"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna. </div>
    <div class="acc-head"> Vestibulum  2</div>
    <div class="acc-body"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna. </div>
  </div>
</div>
Answer:1

I think you should use the next-function instead of the siblings-function:

https://api.jquery.com/next/

<style>
    .projects-list {
      max-width: 600px;
      margin: 0 auto;
      background: #E0E0E0;
      padding: 15px 0;
      font-family: Roboto;
    }
    body {
      margin: 0;
      padding: 0;
    }
    .acc-wrap {
      position: relative;
      width: 100%;
    }
    .acc-wrap > .acc-head {
      float: left;
      width: 100%;
      display: block;
      background-color: #264796;
      padding: 10px;
      color: #fff;
      font-weight: 600;
      border-bottom: 1px solid #ddd;
      transition: all 0.2s linear;
      position: relative;
    }
    .acc-wrap > .acc-head.opened {
      position: relative;
    }
    .acc-wrap > .acc-head.opened:after {
      content: "\f055";
      font-family: fontAwesome;
      position: absolute;
      right: 15px;
    }
    .acc-wrap > .acc-head.closed {
      position: relative;
    }
    .acc-wrap > .acc-head.closed:after {
      content: "\f056";
      font-family: fontAwesome;
      position: absolute;
      right: 15px;
    }
    .acc-body {
      position: relative;
      width: 100%;
      float: left;
      background-color: #fff;
      padding: 10px;
      border-bottom: 1px solid #ddd;
      display: none;
      box-sizing: border-box;
    }
</style>
Answer:2

Add This it is much easy and fast than yours http://www.w3schools.com/Bootstrap/tryit.asp?filename=trybs_collapsible_accordion&stacked=h

Answer:3

Instead of using referencing the elements by class you want to use "this".find("element").attr() etc etc. You are targeting all elements matching the class .acc-head when using this $(".acc-wrap > .acc-head");

Alternatively you could reference the targeted element using $(".acc-wrap > .acc-head.active");

Answer:4

$(".acc-wrap > .acc-head:not(.opened)");

Answer:5

I am modelling the auth layer for a simple react/redux app. On the server side I have an API based on the devise_token_auth gem. I am using fetch to post a sign in request: const JSON_HEADERS = new ...

I am modelling the auth layer for a simple react/redux app. On the server side I have an API based on the devise_token_auth gem. I am using fetch to post a sign in request: const JSON_HEADERS = new ...

I'm trying to implement a messaging application in my game, so instead of clicking on the input text field manually, I want users to only press "enter", write something, then press "enter" again to ...

I'm trying to implement a messaging application in my game, so instead of clicking on the input text field manually, I want users to only press "enter", write something, then press "enter" again to ...

JavaScript UI automation frameworks such as Protractor involves working on asynchronous execution, promises, callbacks, anonymous functions, etc which are probably an overkill for a straight forward ...

JavaScript UI automation frameworks such as Protractor involves working on asynchronous execution, promises, callbacks, anonymous functions, etc which are probably an overkill for a straight forward ...

  1. javascript choose language

I have a public property returned from my code-behind class to aspx page: window.MyWIndow.IsFull = '<%=this.IsFull%>'; In code-behind it is defined this way: public bool IsFull { get; ...

I have a public property returned from my code-behind class to aspx page: window.MyWIndow.IsFull = '<%=this.IsFull%>'; In code-behind it is defined this way: public bool IsFull { get; ...

  1. convert string boolean to boolean python
  2. convert string boolean to boolean javascript
  3. convert string boolean to boolean java
  4. convert string boolean to boolean php
  5. convert string boolean typescript
  6. convert string boolean
  7. convert string boolean c#
  8. convert string to bool
  9. conversion boolean string java
  10. convert string to boolean js
  11. convert string to boolean ruby
  12. convert string to boolean jquery
  13. convert string to boolean vb.net
  14. convert string into boolean javascript
  15. convert string to boolean golang
  16. convert string to boolean angular 6
  17. convert string to boolean powershell
  18. convert string to boolean scala
  19. convert string to boolean angular
  20. convert string to boolean apex