I'm trying to write a script in pure js or jQuery to catch every <div>
with a particular regex in its CSS background-image
property.
<div style="background-image: url('the_regex/http://example.org/image.jpg')>
<div style="background-image: url('the_regex/http://example.org/another.jpg')>
I'm starting with an existing, functional script that collects all <img>
elements that have the regex in the src=""
attribute. It's looking for elements like this:
<img src="the_regex/http://example.org/img.jpg">
<img src="the_regex/http://example.org/img2.jpg">
with this
this.$imgs = $("img[src*='" + this.the_regex + "']");
So this works for <img>
elements, but my site is all <div>
s with background-image
.
From this question I know how to get the url from a given div, but I want to collect all the divs with this regex in the background-image into a single variable, so i can each
them and remove that regex…
Fwiw, the script is sencha-src-fallback.js. It eventually removes the regex from the src if a certain condition is satisfied.