I have a set of span elements on a page. They are positioned with some information that they receive from the backend and the style attribute is changed accordingly with a previous javascipt execution.
It's like a map.
On the map there are several spots and every spot has a name. But some spots might have several names.
<span class="myimages" id="tag-14" style="position: absolute; left: 191px; top: 217px;">hello</span>
<span class="myimages" id="tag-15" style="position: absolute; left: 141px; top: 112px;">bye</span>
<span class="myimages" id="tag-16" style="position: absolute; left: 191px; top: 217px;">welcome</span>
<span class="myimages" id="tag-17" style="position: absolute; left: 50px; top: 12px;">lunch</span>
What I want to do is I want to create groups inside this array of objects so that I can modify them as I wish.
I want to do something like creating an array and then getting the ones who share the same attribute (same position) and then do something which only would affect that group of span elements but not the other ones.
The first part I'm able to fulfill :
function foam()
{
var menus = document.getElementsByClassName("myimages");
for (var i=0; i < menus.length ; i++)
{
menuposition = menus[i].getAttribute("style");
menus[i].setAttribute('style', menuposition+'background-color:pink;');
}
}
But this ofcourse changes the style attribute of every element, I want to be able to make a loop inside a loop, or create conditions or something to fulfill this.
Thanks in advance.
UPDATE: I can't assign a class name automatically. The position information is coming from a flat list of like: "spot name, spot names coordinate on the image" and only info that tells that one spot is the same is the x & y coordinate... It's somehow limiting but it's the case.
Also I'd be modifying a few attributes more than changing just the background color.