You should be able to use document.querySelectorAll()
to target any images you don't want affected, and then add the rwp-not-responsive
class with element.classList.add
For instance, I'll add an unwanted-border
class to all images (the first block of JavaScript below), pretend this is your responsive image plugin.
Then, in the second JavaScript block I'll add the rwp-not-responsive
class to all images that:
- Have
class="people"
- Have
attr="some-attr"
- Have a
src
that contains blur
anywhere in it.
You can use just about any complex selector in querySelectorAll
that you want, such as the CSS Contains
attribute selector: [attribute*="@2x"]
should grab any image with @2x
in the src URL.
// Your Responsive Script, affects all images
images = document.querySelectorAll('img');
for( i = 0, n = images.length; i < n; ++ i ){
images[i].classList.add('unwanted-border');
}
// Code to add rwp-not-responsive class
skipImages = document.querySelectorAll('.people, [attr="some-attr"], [src*="blur"]');
for( i = 0, n = skipImages.length; i < n; ++ i ){
skipImages[i].classList.add('rwp-not-responsive');
}
img.unwanted-border:not(.rwp-not-responsive) {
border: 10px solid #fff;
border-radius: 3px;
box-shadow: 0 10px 20px -8px #000;
}
<img src="https://picsum.photos/200/300/" />
<img class="people" src="https://picsum.photos/200/300/" />
<img attr="some-attr" src="https://picsum.photos/200/300/" />
<img src="https://picsum.photos/200/300/?blur" />