List of All Background Images in DOM

前端 未结 7 1111
旧巷少年郎
旧巷少年郎 2020-12-29 12:00

What\'s the best way to find all of the background images on a given page using javascript?

The ideal end result would be an array of all of the url\'s.

7条回答
  •  长发绾君心
    2020-12-29 12:36

    One of the way is to look through all document object and get there styles. Then test style.background attribute on "url(" string and if it matches then get path between "url(" and ")" and put it into array. Algorithm for JS. Try to do it yourself. Will find troubles - came with code.

提交回复
热议问题