Skip to content
Advertisement

want to use plus minus icon at foreach loop at collapse expend using javascript [closed]

Below i have a foreach loop, there i use icon plus class. After click my javascript function myFunction(); i want to add minus icon.

$i=0; $j=0; $k=0; $l=0;
foreach ($cat_group_head_first as $ccgrouphead) {
?>
<span class="acc-trigger" style="width: 100% !important;">
   <a onclick="myFunction('#cat_head<?php echo $i=$i+1;?>');">
   <b>{{$ccgrouphead->GroupHead}} 
    
      <!-- want to use plus minus icon below icon class-->
      <i class="glyphicon glyphicon-plus"></i>
   </b>
   </a>
</span>
<?php
}

Advertisement

Answer

I have got my question solution:

 <script type="text/javascript">
  $('.acc-trigger').click(function() { // when a .myDiv is clicked

  $(this).toggleClass('active')
  })
</script>

css:

.acc-trigger{ background: url(https://bdtender.com/images/accordion-plus.png) no-repeat right 50%; } .acc-trigger.active{ background: url(https://bdtender.com/images/accordion-minus.png) no-repeat right 50%; }

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement