I made the output of posts on accordions on WP, everything works, but before me I had a script in the layout that was supposed to hang the active class in a div with the panel panel-default class that I needed to design css, everything worked in the layout It does not work and the class does not add, there is no error in the inspector and the script is present. Here is the accordion cycle

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> <?php if (have_posts()): while (have_posts()): the_post(); ?> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingOne"> <h4 class="panel-title"> <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#<?php the_ID(); ?>" aria-expanded="false" aria-controls="collapseTwo"> <?php the_title(); ?> </a> <span class="collapsed caret" data-toggle="collapse" data-parent="#accordion" href="#<?php the_ID(); ?>" aria-expanded="false" aria-controls="collapseTwo" class="caret"></span> </h4> </div> <div id="<?php the_ID(); ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne"> <div class="panel-body"> <?php the_content(); ?> </div> </div> </div> <?php endwhile; endif; ?> </div> 

and this is the script itself, it is connected but not working

 (function () { $(".panel").on("show.bs.collapse hide.bs.collapse", function (e) { if (e.type == 'show') { $(this).addClass('active'); } else { $(this).removeClass('active'); } }); }).call(this); 

  • html should be provided without php-inserts - Jean-Claude
  • This is WP, what are you talking about? - fisher

0