I have a loop that creates multiple divs
with the class panel
.
@for(comment <- event.getCommentsSorted()) {
However, when I try to manipulate each of these divs
using jQuery's .each
, only the first two divs
are selected.
$(window).on('load', function() {
$(".panel").each(function (index) {
alert(index);
$(this).height($(this)[index].scrollHeight - 12);
});
});
The remaining three divs
seem to be missing.
https://i.sstatic.net/hpLmq.png
I initially thought it could be due to the script executing before all divs
are created, but since I'm using load
, it should run after the page has fully loaded.
I've also tried utilizing .ready
and varying the number of generated divs
, but I still only target the first two elements.
Why am I only able to select the first two elements, and is there a way to target all elements?