I have this jquery code, what it does is that it is executed when a link is clicked:
<script> var num = 0; var texto; $(document).ready(function(){ $('body').on('click', '#accordion a', function(){ num = $(this).attr('id'); temas(num); }); }); function temas(num) { $("#collapse" + num).on("hide.bs.collapse", function(){ $(".enlace" + num).html("<span class='fa fa-toggle-down'></span> <a class='card-link' data-toggle='collapse' data-target='#collapse" + num + "' href='#collapse" + num + '"> " + texto + "</a>"); }); $("#collapse" + num).on("show.bs.collapse", function(){ $(".enlace" + num).html("<span class='fa fa-toggle-up'></span> <a class='card-link' data-toggle='collapse' data-target='#collapse" + num + "' href='#collapse" + num + "'"> " + texto + "</a>"); }); } </script>
Those links have an id and I get it by clicking on one of them, when I click on a link for the first time if it gets the id but when I click on that same link more than once it marks me indefinitely.
Why is that happening?