So I want to insert a span element x times based on the length of another html element as with a for loop. I am getting the correct amount returned but I get undefined in the html. I know I am doing something wrong in the loop, but can't see where? I have looped over arrays and returned the value before via a for loop, but inserting an element based on the count loop I have not. So I should be inserting the <span class="pagination-bullet"></span> say 4 times based on count. In html i get <<s<sp<spa So definitely something is not right.
var counterElem = document.querySelectorAll('.slider-carousel-slide');
var count = counterElem.length;
var paginationCount = count;
var parentElem = document.querySelector('#main-carousel-pagination');
var paginationElement = document.createElement('SPAN');
paginationElement.innerHTML = '<span class="pagination-bullet"></span>';
var insert = '';
for (i = 0; i < count; i++ ) {
insert += `<span class="swiper-pagination-bullet">`[i];
parentElem.append(insert);
}
So what I would expect is if count = 4, then the html would be:
<span class="pagination-bullet"></span>
<span class="pagination-bullet"></span>
<span class="pagination-bullet"></span>
<span class="pagination-bullet"></span>
t">`[i];<-- what is that [i] ??? doing there? Where is the closing</span>?[i]supposed to be doing in your eyes?