How to find all tags with the same spinner attribute and replace them all with the value of this attribute.

In my example, only the first attribute is edited. How to make it work on all tags with this attribute?

And if you can another example on coffeescript

i = 0; tags = document.getElementsByTagName('*'); tag = null; replacementAttr = function() { var image; while ( tag = tags[i++]) { if (this.tag.getAttribute('spinner') != null) { image = tag.getAttribute('spinner'); tag.style.backgroundImage = "url( " + image + " )"; return; } } }; replacementAttr(); 
 div{ border: 1px solid; background: #d7d7d7; width: 100%; height: 100px; } 
 <div spinner="http://i.vimeocdn.com/video/394424921_1280x720.jpg">spinner</div> <div spinner="http://www.fiji.travel/sites/default/files//styles/hero-full/public/sports-illustrated-fiji-banner.jpg?itok=v4WCGsHC">spinner</div> <div spinner="http://fanaticsview.com/wp-content/uploads/2016/03/hannah-daviss-si-swimsuit-2016-s.jpg">spinner</div> 

    1 answer 1

    it turned out that the whole thing in return and i

     i = 0; tags = document.getElementsByTagName('*'); tag = null; replacementAttr = function() { var image; while (i < tags.length) { tag = tags[i] if (tag.getAttribute('spinner') != null) { image = tag.getAttribute('spinner'); tag.style.backgroundImage = "url( " + image + " )"; } i++ } }; replacementAttr(); 
     div{ border: 1px solid; background: #d7d7d7; width: 100%; height: 100px; } 
     <div spinner="http://i.vimeocdn.com/video/394424921_1280x720.jpg">spinner</div> <div spinner="http://www.fiji.travel/sites/default/files//styles/hero-full/public/sports-illustrated-fiji-banner.jpg?itok=v4WCGsHC">spinner</div> <div spinner="http://fanaticsview.com/wp-content/uploads/2016/03/hannah-daviss-si-swimsuit-2016-s.jpg">spinner</div>