Let's say that in this case I have 4 divs called ".CountThese", and I wanted to do just that, get the number of elements with this particular class, and then add the div as many times as there were ". CountThese" (4 times in this case)
This is html:
<div class="CountThese"></div>
<div class="CountThese"></div>
<div class="CountThese"></div>
<div class="CountThese"></div>
<div class="appendHere"></div>
This will be the result:
<div class="CountThese"></div>
<div class="CountThese"></div>
<div class="CountThese"></div>
<div class="CountThese"></div>
<div class="appendHere">
<div class="appendedDIVs"></div>
<div class="appendedDIVs"></div>
<div class="appendedDIVs"></div>
<div class="appendedDIVs"></div>
</div>
I only have so far that I found out that you can count the number of elements like this:
function divcount() {
var Count = $('.CountThese').length();
document.write(Count)
}
I think I don’t know how to use it. I seriously don't know how I could use this number to add divs or anything else in this case.
How can this be achieved?
source
share