I have been working on code to tag images. I was able to insert the tags and for each inserted tag a small box is created and tagname will be displayed inside. What I would like to do is, to have different color for each of the box created.
var html = "<div class='inputtag'><i class='fa fa-eye' aria-hidden='true'></i><i class='fa fa-trash-alt' aria-hidden='true'></i><span>" + input + "</span><input type='hidden' name='tag_name[]' value='" + input + "'></div>";
$('.tags').append(html);
var theColors = []
document.querySelectorAll(".inputtag").forEach((el, idx) =>
theColors.push("#" + ((1 << 24) * Math.random() | 0).toString(16)); el.style.borderColor = theColors[idx]
)
.inputtag>i {
margin - right: 4 px;
}
.inputtag {
border - radius: 4 px;
border: 1 px solid skyblue;
color: #000;
padding: 2px 8px;
width: max-content;
text-align: center;
cursor: pointer;
margin: 4px 4px;
float: left;
}
In the above Javascript code i tried to get different border color for the elements inside div, but the color keeps changing after each new entry. I have attached the images below to explain it better.
Image 1:
In this image 1 , u can see the elements with two different colors. These colors change when i add a new element. i.e., for each element added inside the Div, the border color for each element keep changing.
Image 2 :
The image 2 shows the change in the border color for the elements. What i would like to have is to have different fixed colors for each of the elements inside the Div, so they don't change color on adding a new element.
Can someone help me with this problem.

