title: grouping inside a for loop & modifying span elements according to style attribute
body: <p>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.</p>
  
  <p>It's like a map.</p>
  
  <p>On the map there are several spots and every spot has a name.
  But some spots might have several names.</p>
  
  <pre><code>&lt;span class="myimages" id="tag-14" style="position: absolute; left: 191px; top: 217px;"&gt;hello&lt;/span&gt;
  &lt;span class="myimages" id="tag-15" style="position: absolute; left: 141px; top: 112px;"&gt;bye&lt;/span&gt;
  &lt;span class="myimages" id="tag-16" style="position: absolute; left: 191px; top: 217px;"&gt;welcome&lt;/span&gt;
  &lt;span class="myimages" id="tag-17" style="position: absolute; left: 50px; top: 12px;"&gt;lunch&lt;/span&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>The first part I'm able to fulfill :</p>
  
  <pre><code>function foam()
      {
      var menus = document.getElementsByClassName("myimages");
  
           for (var i=0; i &lt; menus.length ; i++)
              {
                  menuposition = menus[i].getAttribute("style");
                  menus[i].setAttribute('style', menuposition+'background-color:pink;');
              }
      }
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>UPDATE:</strong>
  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 &amp; y coordinate... It's somehow limiting but it's the case.</p>
  
  <p>Also I'd be modifying  a few attributes more than changing just the background color.</p>