The problem:
I've got a few divs with the same class. I want to place a number (start from 2 to --) before each div.
This is what I tried:
let optionNumber = $(".product-configure-custom-option")
$('.product-configure-custom').each(function () {
if ( $(this).find("div.product-configure-custom-option").length ) {
$('<div class="title-number float-left text-center mr-2">' + $(optionNumber).length + '</div>').insertBefore(optionNumber)
}
});
.product-configure-custom-option{
float:right;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
<div class="product-configure-custom">
<div class="product-configure-custom-option">Option 2</div>
<div class="product-configure-custom-option">Option 3</div>
<div class="product-configure-custom-option">Option 4</div>
<div class="product-configure-custom-option">Option 5</div>
<div class="product-configure-custom-option">Option 6</div>
<div class="product-configure-custom-option">Option 7</div>
</div>
</div>
What I want the result to be:
- Option Two
- Option Three
- Option Four