I am facing an issue with dynamically adding a class to my code. I have been using the addClass method, but it is not meeting my requirements as expected. Below is the snippet of my code:
<div id="form-copy">
<div class="abc">
Here resides some important code....
<div>
<div>
This is what I have tried so far:
var p = 0;
for(var i =0; i<n;i++){
$(".abc:first").clone(true).appendTo("#form-copy")
$(".abc").addClass( "dynamicClass"+ ++p);
}
The current output looks like this:
If n=3
<div class="abc dynamicClass1 dynamicClass2 dynamicClass3">...</div>
<div class="abc dynamicClass1 dynamicClass2 dynamicClass3">...</div>
<div class="abc dynamicClass1 dynamicClass2 dynamicClass3">...</div>
However, I am aiming for the following desired output:
If n=3
<div class="abc dynamicClass1">...</div>
<div class="abc dynamicClass2">...</div>
<div class="abc dynamicClass3">...</div>
Please assist me in achieving the desired output. Thank you.