i have this func :
$(".card").each(function() {
$(this)
.closest('.collapse-group')
.find('.btn')
.toggle($(this).text().length > 16);
});
But I need to transform it when the elements are dynamically appended, for example i know how it to do for click func, but on EACH - no:
$(document).on('click', '.btn', function(e) {
e.preventDefault();
var $this = $(this);
var $collapse = $this.closest('.collapse-group').find('.collapse');
$collapse.collapse('toggle');
}); //- this func works
$(document).on('each', ".card", function() {
$(this)
.closest('.collapse-group')
.find('.btn')
.toggle($(this).text().length > 16);
});//??? - this func does not work
insert it right under the block where I append the cards does not work:
var card =
`<hr>
<h3>
<p class="text-center " >${title}</p>
</h3>
<img class="col-12 ml-auto col-12 mr-auto" src=${images}>
<div class="span4 collapse-group">
<div class="text-center">
<p><a class="btn btn-md btn-outline-dark btn-square" href="#">Check »</a></p>
</div>
<div class="collapse">
<div class="card card-body">
${text}
</div>
</div>
</div>`
$('.container').append(card)
$(document).find(".card").each(function() {
$(this)
.closest('.collapse-group')
.find('.btn')
.toggle($(this).text().length > 16);
});
each()logic in a function and then call that function right after you append the new elements.