Skip to content

Instantly share code, notes, and snippets.

@timbryandev
Created January 20, 2023 10:09
Show Gist options
  • Save timbryandev/7c16a68aedd71e0d8b2e0be745b56276 to your computer and use it in GitHub Desktop.
Save timbryandev/7c16a68aedd71e0d8b2e0be745b56276 to your computer and use it in GitHub Desktop.
JS snippets
// replace all images with STARWARS
// document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('img').forEach(img => {
img.removeAttribute('srcset')
img.setAttribute(
'src',
'https://images.unsplash.com/photo-1651654325764-205a848bbea0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxfDB8MXxyYW5kb218MHx8fHx8fHx8MTY1MzQ2NTA2Mg&ixlib=rb-1.2.1&q=80&w=1080'
)
})
document
.querySelectorAll('[style*=url]')
.forEach(
el =>
(el.style.backgroundImage =
'url(https://images.unsplash.com/photo-1651654325764-205a848bbea0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxfDB8MXxyYW5kb218MHx8fHx8fHx8MTY1MzQ2NTA2Mg&ixlib=rb-1.2.1&q=80&w=1080)')
)
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment