You can achieve this by using the querySelectorAll
method to select all the div
elements with a background-image
property or img
elements with a src
property that matches the specified URL. Then, you can loop through the selection and update the URL with the new value.
Here's an example code snippet that demonstrates this approach:
index.tsx635 chars18 lines
In this code, we first define the old and new URLs using variables. We then select all of the div
and img
elements that have the old URL in either the background-image
or src
property using the querySelectorAll
method.
We loop through each selection using the forEach
method and update the background-image
or src
property using the replace
method to replace the old URL with the new URL.
Note that the querySelectorAll
method returns a NodeList
, so we can use the forEach
method to loop through each element.
gistlibby LogSnag