how to have the first accordion in each section start open, but ALSO behave independently of the other...












4


















    //Accordian jQuery
$(document).ready(function () {
$('.accordian-content').hide();
$(".accordian-content:first").slideDown();
$('.accordian-title').click(function () {
const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
$('.accordian-title-icon').removeClass('accordian-title-icon-open');
$('.accordian-content').not($(this).next('.accordian-content')).slideUp();
$(this).next('.accordian-content').slideToggle();
if (!flag) {
$(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

//Add this code
/* thisE = $(this)
setTimeout(function () {
$('html, body').animate({
scrollTop: thisE.offset().top -75 }, 'slow');
}, 450)//Wait for toggle animation to finish */

} else {
$(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
}

});
});

     .priority-lists {width:100%;}
.accordian-title {
width: 100%;
cursor: pointer;
padding: 20px 10px 20px 20px;
font-size: 20px;
}

.accordian-item {
color: rgba(40, 150, 211, 1);
margin: 10px auto;
width: 100%;
max-width: 530px;
background: #fff;
border: solid 1px #f0f0f0;
border-radius: 5px;
-webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
-moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
-webkit-transition: all .1s ease;
-moz-transition: all .1s ease;
-o-transition: all .1s ease;
transition: all .1s ease;
}

.accordian-item:hover {
-webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
}

.accordian .accordian-item .accordian-title .accordian-title-icon {
background: #dedede;
border-radius: 50%;
width: 25px;
height: 25px;
display: inline-block;
text-align: center;
color: white;
font-weight: 700;
margin-right: 0;
padding: 0 0 0 1px;
position: relative;
vertical-align: top;
float: right;
opacity: 1;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
}



.accordian .accordian-item .accordian-title .accordian-title-icon:before {
content: '+';
display: block;
position: absolute;
width: 100%;
font-size: 21px;
line-height: 24px;
margin: -1px;
}

.accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
display: none;
}

.accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
content: '-';
margin-top: -3px;
margin-left: -1px;
display: block;
position: absolute;
text-align: center;
width: 100%;
}

.accordian-content {
color: #3a3a3a;
padding: 0 20px 20px;
text-align: left;
}

.accordian-content2 {
color: #3a3a3a;
padding: 0 20px 20px;
text-align: left;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<h2>SECTION 2</h2>

<div class="priority-lists">
<div class="accordian">

<div class="accordian-item">
<div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
<div class="accordian-content" style="display: none;">
<p>This is a sentence.</p>
</div>
</div>

<div class="accordian-item">
<div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
<div class="accordian-content" style="display: none;">
<p>This is a sentence</p>
</div>
</div>

<div class="accordian-item">
<div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
<div class="accordian-content" style="display: none;">
<p>this is a sentence</p>
</div>
</div>

</div>

<h2>SECTION 2</h2>

<div class="priority-lists">
<div class="accordian">

<div class="accordian-item">
<div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
<div class="accordian-content" style="display: none;">
<p>This is a sentence.</p>
</div>
</div>

<div class="accordian-item">
<div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
<div class="accordian-content" style="display: none;">
<p>This is a sentence</p>
</div>
</div>

<div class="accordian-item">
<div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
<div class="accordian-content" style="display: none;">
<p>this is a sentence</p>
</div>
</div>

</div>





Im trying to have the first accordion in each section start open, but ALSO behave independently of the other section (ie, when you open close accordion items in one section, the other section is unaffected and vice-versa.



I've added $(".accordian-content:first").slideDown(); and this works but is only applied to the very first one










share|improve this question





























    4


















        //Accordian jQuery
    $(document).ready(function () {
    $('.accordian-content').hide();
    $(".accordian-content:first").slideDown();
    $('.accordian-title').click(function () {
    const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
    $('.accordian-title-icon').removeClass('accordian-title-icon-open');
    $('.accordian-content').not($(this).next('.accordian-content')).slideUp();
    $(this).next('.accordian-content').slideToggle();
    if (!flag) {
    $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

    //Add this code
    /* thisE = $(this)
    setTimeout(function () {
    $('html, body').animate({
    scrollTop: thisE.offset().top -75 }, 'slow');
    }, 450)//Wait for toggle animation to finish */

    } else {
    $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
    }

    });
    });

         .priority-lists {width:100%;}
    .accordian-title {
    width: 100%;
    cursor: pointer;
    padding: 20px 10px 20px 20px;
    font-size: 20px;
    }

    .accordian-item {
    color: rgba(40, 150, 211, 1);
    margin: 10px auto;
    width: 100%;
    max-width: 530px;
    background: #fff;
    border: solid 1px #f0f0f0;
    border-radius: 5px;
    -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
    -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
    box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
    -webkit-transition: all .1s ease;
    -moz-transition: all .1s ease;
    -o-transition: all .1s ease;
    transition: all .1s ease;
    }

    .accordian-item:hover {
    -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
    -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
    box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
    }

    .accordian .accordian-item .accordian-title .accordian-title-icon {
    background: #dedede;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    display: inline-block;
    text-align: center;
    color: white;
    font-weight: 700;
    margin-right: 0;
    padding: 0 0 0 1px;
    position: relative;
    vertical-align: top;
    float: right;
    opacity: 1;
    -webkit-transition: all .3s ease;
    -moz-transition: all .3s ease;
    -o-transition: all .3s ease;
    }



    .accordian .accordian-item .accordian-title .accordian-title-icon:before {
    content: '+';
    display: block;
    position: absolute;
    width: 100%;
    font-size: 21px;
    line-height: 24px;
    margin: -1px;
    }

    .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
    display: none;
    }

    .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
    content: '-';
    margin-top: -3px;
    margin-left: -1px;
    display: block;
    position: absolute;
    text-align: center;
    width: 100%;
    }

    .accordian-content {
    color: #3a3a3a;
    padding: 0 20px 20px;
    text-align: left;
    }

    .accordian-content2 {
    color: #3a3a3a;
    padding: 0 20px 20px;
    text-align: left;
    }

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <h2>SECTION 2</h2>

    <div class="priority-lists">
    <div class="accordian">

    <div class="accordian-item">
    <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
    <div class="accordian-content" style="display: none;">
    <p>This is a sentence.</p>
    </div>
    </div>

    <div class="accordian-item">
    <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
    <div class="accordian-content" style="display: none;">
    <p>This is a sentence</p>
    </div>
    </div>

    <div class="accordian-item">
    <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
    <div class="accordian-content" style="display: none;">
    <p>this is a sentence</p>
    </div>
    </div>

    </div>

    <h2>SECTION 2</h2>

    <div class="priority-lists">
    <div class="accordian">

    <div class="accordian-item">
    <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
    <div class="accordian-content" style="display: none;">
    <p>This is a sentence.</p>
    </div>
    </div>

    <div class="accordian-item">
    <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
    <div class="accordian-content" style="display: none;">
    <p>This is a sentence</p>
    </div>
    </div>

    <div class="accordian-item">
    <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
    <div class="accordian-content" style="display: none;">
    <p>this is a sentence</p>
    </div>
    </div>

    </div>





    Im trying to have the first accordion in each section start open, but ALSO behave independently of the other section (ie, when you open close accordion items in one section, the other section is unaffected and vice-versa.



    I've added $(".accordian-content:first").slideDown(); and this works but is only applied to the very first one










    share|improve this question



























      4












      4








      4











          //Accordian jQuery
      $(document).ready(function () {
      $('.accordian-content').hide();
      $(".accordian-content:first").slideDown();
      $('.accordian-title').click(function () {
      const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
      $('.accordian-title-icon').removeClass('accordian-title-icon-open');
      $('.accordian-content').not($(this).next('.accordian-content')).slideUp();
      $(this).next('.accordian-content').slideToggle();
      if (!flag) {
      $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

      //Add this code
      /* thisE = $(this)
      setTimeout(function () {
      $('html, body').animate({
      scrollTop: thisE.offset().top -75 }, 'slow');
      }, 450)//Wait for toggle animation to finish */

      } else {
      $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
      }

      });
      });

           .priority-lists {width:100%;}
      .accordian-title {
      width: 100%;
      cursor: pointer;
      padding: 20px 10px 20px 20px;
      font-size: 20px;
      }

      .accordian-item {
      color: rgba(40, 150, 211, 1);
      margin: 10px auto;
      width: 100%;
      max-width: 530px;
      background: #fff;
      border: solid 1px #f0f0f0;
      border-radius: 5px;
      -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -webkit-transition: all .1s ease;
      -moz-transition: all .1s ease;
      -o-transition: all .1s ease;
      transition: all .1s ease;
      }

      .accordian-item:hover {
      -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon {
      background: #dedede;
      border-radius: 50%;
      width: 25px;
      height: 25px;
      display: inline-block;
      text-align: center;
      color: white;
      font-weight: 700;
      margin-right: 0;
      padding: 0 0 0 1px;
      position: relative;
      vertical-align: top;
      float: right;
      opacity: 1;
      -webkit-transition: all .3s ease;
      -moz-transition: all .3s ease;
      -o-transition: all .3s ease;
      }



      .accordian .accordian-item .accordian-title .accordian-title-icon:before {
      content: '+';
      display: block;
      position: absolute;
      width: 100%;
      font-size: 21px;
      line-height: 24px;
      margin: -1px;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
      display: none;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
      content: '-';
      margin-top: -3px;
      margin-left: -1px;
      display: block;
      position: absolute;
      text-align: center;
      width: 100%;
      }

      .accordian-content {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      .accordian-content2 {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>





      Im trying to have the first accordion in each section start open, but ALSO behave independently of the other section (ie, when you open close accordion items in one section, the other section is unaffected and vice-versa.



      I've added $(".accordian-content:first").slideDown(); and this works but is only applied to the very first one










      share|improve this question



















          //Accordian jQuery
      $(document).ready(function () {
      $('.accordian-content').hide();
      $(".accordian-content:first").slideDown();
      $('.accordian-title').click(function () {
      const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
      $('.accordian-title-icon').removeClass('accordian-title-icon-open');
      $('.accordian-content').not($(this).next('.accordian-content')).slideUp();
      $(this).next('.accordian-content').slideToggle();
      if (!flag) {
      $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

      //Add this code
      /* thisE = $(this)
      setTimeout(function () {
      $('html, body').animate({
      scrollTop: thisE.offset().top -75 }, 'slow');
      }, 450)//Wait for toggle animation to finish */

      } else {
      $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
      }

      });
      });

           .priority-lists {width:100%;}
      .accordian-title {
      width: 100%;
      cursor: pointer;
      padding: 20px 10px 20px 20px;
      font-size: 20px;
      }

      .accordian-item {
      color: rgba(40, 150, 211, 1);
      margin: 10px auto;
      width: 100%;
      max-width: 530px;
      background: #fff;
      border: solid 1px #f0f0f0;
      border-radius: 5px;
      -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -webkit-transition: all .1s ease;
      -moz-transition: all .1s ease;
      -o-transition: all .1s ease;
      transition: all .1s ease;
      }

      .accordian-item:hover {
      -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon {
      background: #dedede;
      border-radius: 50%;
      width: 25px;
      height: 25px;
      display: inline-block;
      text-align: center;
      color: white;
      font-weight: 700;
      margin-right: 0;
      padding: 0 0 0 1px;
      position: relative;
      vertical-align: top;
      float: right;
      opacity: 1;
      -webkit-transition: all .3s ease;
      -moz-transition: all .3s ease;
      -o-transition: all .3s ease;
      }



      .accordian .accordian-item .accordian-title .accordian-title-icon:before {
      content: '+';
      display: block;
      position: absolute;
      width: 100%;
      font-size: 21px;
      line-height: 24px;
      margin: -1px;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
      display: none;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
      content: '-';
      margin-top: -3px;
      margin-left: -1px;
      display: block;
      position: absolute;
      text-align: center;
      width: 100%;
      }

      .accordian-content {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      .accordian-content2 {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>





      Im trying to have the first accordion in each section start open, but ALSO behave independently of the other section (ie, when you open close accordion items in one section, the other section is unaffected and vice-versa.



      I've added $(".accordian-content:first").slideDown(); and this works but is only applied to the very first one






          //Accordian jQuery
      $(document).ready(function () {
      $('.accordian-content').hide();
      $(".accordian-content:first").slideDown();
      $('.accordian-title').click(function () {
      const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
      $('.accordian-title-icon').removeClass('accordian-title-icon-open');
      $('.accordian-content').not($(this).next('.accordian-content')).slideUp();
      $(this).next('.accordian-content').slideToggle();
      if (!flag) {
      $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

      //Add this code
      /* thisE = $(this)
      setTimeout(function () {
      $('html, body').animate({
      scrollTop: thisE.offset().top -75 }, 'slow');
      }, 450)//Wait for toggle animation to finish */

      } else {
      $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
      }

      });
      });

           .priority-lists {width:100%;}
      .accordian-title {
      width: 100%;
      cursor: pointer;
      padding: 20px 10px 20px 20px;
      font-size: 20px;
      }

      .accordian-item {
      color: rgba(40, 150, 211, 1);
      margin: 10px auto;
      width: 100%;
      max-width: 530px;
      background: #fff;
      border: solid 1px #f0f0f0;
      border-radius: 5px;
      -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -webkit-transition: all .1s ease;
      -moz-transition: all .1s ease;
      -o-transition: all .1s ease;
      transition: all .1s ease;
      }

      .accordian-item:hover {
      -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon {
      background: #dedede;
      border-radius: 50%;
      width: 25px;
      height: 25px;
      display: inline-block;
      text-align: center;
      color: white;
      font-weight: 700;
      margin-right: 0;
      padding: 0 0 0 1px;
      position: relative;
      vertical-align: top;
      float: right;
      opacity: 1;
      -webkit-transition: all .3s ease;
      -moz-transition: all .3s ease;
      -o-transition: all .3s ease;
      }



      .accordian .accordian-item .accordian-title .accordian-title-icon:before {
      content: '+';
      display: block;
      position: absolute;
      width: 100%;
      font-size: 21px;
      line-height: 24px;
      margin: -1px;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
      display: none;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
      content: '-';
      margin-top: -3px;
      margin-left: -1px;
      display: block;
      position: absolute;
      text-align: center;
      width: 100%;
      }

      .accordian-content {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      .accordian-content2 {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>





          //Accordian jQuery
      $(document).ready(function () {
      $('.accordian-content').hide();
      $(".accordian-content:first").slideDown();
      $('.accordian-title').click(function () {
      const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
      $('.accordian-title-icon').removeClass('accordian-title-icon-open');
      $('.accordian-content').not($(this).next('.accordian-content')).slideUp();
      $(this).next('.accordian-content').slideToggle();
      if (!flag) {
      $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

      //Add this code
      /* thisE = $(this)
      setTimeout(function () {
      $('html, body').animate({
      scrollTop: thisE.offset().top -75 }, 'slow');
      }, 450)//Wait for toggle animation to finish */

      } else {
      $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
      }

      });
      });

           .priority-lists {width:100%;}
      .accordian-title {
      width: 100%;
      cursor: pointer;
      padding: 20px 10px 20px 20px;
      font-size: 20px;
      }

      .accordian-item {
      color: rgba(40, 150, 211, 1);
      margin: 10px auto;
      width: 100%;
      max-width: 530px;
      background: #fff;
      border: solid 1px #f0f0f0;
      border-radius: 5px;
      -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
      -webkit-transition: all .1s ease;
      -moz-transition: all .1s ease;
      -o-transition: all .1s ease;
      transition: all .1s ease;
      }

      .accordian-item:hover {
      -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon {
      background: #dedede;
      border-radius: 50%;
      width: 25px;
      height: 25px;
      display: inline-block;
      text-align: center;
      color: white;
      font-weight: 700;
      margin-right: 0;
      padding: 0 0 0 1px;
      position: relative;
      vertical-align: top;
      float: right;
      opacity: 1;
      -webkit-transition: all .3s ease;
      -moz-transition: all .3s ease;
      -o-transition: all .3s ease;
      }



      .accordian .accordian-item .accordian-title .accordian-title-icon:before {
      content: '+';
      display: block;
      position: absolute;
      width: 100%;
      font-size: 21px;
      line-height: 24px;
      margin: -1px;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
      display: none;
      }

      .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
      content: '-';
      margin-top: -3px;
      margin-left: -1px;
      display: block;
      position: absolute;
      text-align: center;
      width: 100%;
      }

      .accordian-content {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      .accordian-content2 {
      color: #3a3a3a;
      padding: 0 20px 20px;
      text-align: left;
      }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>

      <h2>SECTION 2</h2>

      <div class="priority-lists">
      <div class="accordian">

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence.</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>This is a sentence</p>
      </div>
      </div>

      <div class="accordian-item">
      <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
      <div class="accordian-content" style="display: none;">
      <p>this is a sentence</p>
      </div>
      </div>

      </div>






      javascript jquery






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 18:58







      C Davies

















      asked Nov 17 '18 at 19:28









      C DaviesC Davies

      427




      427
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Instead of close all of the .accordian-content elements - you would want to close only those that are part of the current accordion:



          $(this).parents('.accordian').find('.accordian-content')


          Here is the fix in your code:






          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>





          In order to set the first element in each accordion to be open I used



          $(".accordian .accordian-item:first-child .accordian-content").slideDown();





          share|improve this answer


























          • thanks so much! that did the trick

            – C Davies
            Nov 20 '18 at 19:09











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354768%2fhow-to-have-the-first-accordion-in-each-section-start-open-but-also-behave-inde%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Instead of close all of the .accordian-content elements - you would want to close only those that are part of the current accordion:



          $(this).parents('.accordian').find('.accordian-content')


          Here is the fix in your code:






          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>





          In order to set the first element in each accordion to be open I used



          $(".accordian .accordian-item:first-child .accordian-content").slideDown();





          share|improve this answer


























          • thanks so much! that did the trick

            – C Davies
            Nov 20 '18 at 19:09
















          1














          Instead of close all of the .accordian-content elements - you would want to close only those that are part of the current accordion:



          $(this).parents('.accordian').find('.accordian-content')


          Here is the fix in your code:






          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>





          In order to set the first element in each accordion to be open I used



          $(".accordian .accordian-item:first-child .accordian-content").slideDown();





          share|improve this answer


























          • thanks so much! that did the trick

            – C Davies
            Nov 20 '18 at 19:09














          1












          1








          1







          Instead of close all of the .accordian-content elements - you would want to close only those that are part of the current accordion:



          $(this).parents('.accordian').find('.accordian-content')


          Here is the fix in your code:






          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>





          In order to set the first element in each accordion to be open I used



          $(".accordian .accordian-item:first-child .accordian-content").slideDown();





          share|improve this answer















          Instead of close all of the .accordian-content elements - you would want to close only those that are part of the current accordion:



          $(this).parents('.accordian').find('.accordian-content')


          Here is the fix in your code:






          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>





          In order to set the first element in each accordion to be open I used



          $(".accordian .accordian-item:first-child .accordian-content").slideDown();





          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>





          //Accordian jQuery
          $(document).ready(function () {
          $('.accordian-content').hide();
          $(".accordian .accordian-item:first-child .accordian-content").slideDown();
          $('.accordian-title').click(function () {
          const flag = $(this).find('.accordian-title-icon').hasClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-title-icon').removeClass('accordian-title-icon-open');
          $(this).parents('.accordian').find('.accordian-content').not($(this).next('.accordian-content')).slideUp();
          $(this).next('.accordian-content').slideToggle();
          if (!flag) {
          $(this).find('.accordian-title-icon').addClass('accordian-title-icon-open')

          //Add this code
          /* thisE = $(this)
          setTimeout(function () {
          $('html, body').animate({
          scrollTop: thisE.offset().top -75 }, 'slow');
          }, 450)//Wait for toggle animation to finish */

          } else {
          $(this).find('.accordian-title-icon').removeClass('accordian-title-icon-open')
          }

          });
          });

          .priority-lists {width:100%;}
          .accordian-title {
          width: 100%;
          cursor: pointer;
          padding: 20px 10px 20px 20px;
          font-size: 20px;
          }

          .accordian-item {
          color: rgba(40, 150, 211, 1);
          margin: 10px auto;
          width: 100%;
          max-width: 530px;
          background: #fff;
          border: solid 1px #f0f0f0;
          border-radius: 5px;
          -webkit-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -moz-box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          box-shadow: -4px 4px 5px 0px rgba(0,0,0,0.29);
          -webkit-transition: all .1s ease;
          -moz-transition: all .1s ease;
          -o-transition: all .1s ease;
          transition: all .1s ease;
          }

          .accordian-item:hover {
          -webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          -moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.5);
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon {
          background: #dedede;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          display: inline-block;
          text-align: center;
          color: white;
          font-weight: 700;
          margin-right: 0;
          padding: 0 0 0 1px;
          position: relative;
          vertical-align: top;
          float: right;
          opacity: 1;
          -webkit-transition: all .3s ease;
          -moz-transition: all .3s ease;
          -o-transition: all .3s ease;
          }



          .accordian .accordian-item .accordian-title .accordian-title-icon:before {
          content: '+';
          display: block;
          position: absolute;
          width: 100%;
          font-size: 21px;
          line-height: 24px;
          margin: -1px;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:before {
          display: none;
          }

          .accordian .accordian-item .accordian-title .accordian-title-icon-open:after {
          content: '-';
          margin-top: -3px;
          margin-left: -1px;
          display: block;
          position: absolute;
          text-align: center;
          width: 100%;
          }

          .accordian-content {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          .accordian-content2 {
          color: #3a3a3a;
          padding: 0 20px 20px;
          text-align: left;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>

          <h2>SECTION 2</h2>

          <div class="priority-lists">
          <div class="accordian">

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence.</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>This is a sentence</p>
          </div>
          </div>

          <div class="accordian-item">
          <div class="accordian-title">TITLE<span class="accordian-title-icon"></span></div>
          <div class="accordian-content" style="display: none;">
          <p>this is a sentence</p>
          </div>
          </div>

          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 '18 at 20:44

























          answered Nov 17 '18 at 20:35









          DekelDekel

          42.7k54667




          42.7k54667













          • thanks so much! that did the trick

            – C Davies
            Nov 20 '18 at 19:09



















          • thanks so much! that did the trick

            – C Davies
            Nov 20 '18 at 19:09

















          thanks so much! that did the trick

          – C Davies
          Nov 20 '18 at 19:09





          thanks so much! that did the trick

          – C Davies
          Nov 20 '18 at 19:09


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354768%2fhow-to-have-the-first-accordion-in-each-section-start-open-but-also-behave-inde%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)