I Need to filter out all images with src domain like abs.twimg.com
<img class="ProfileCard-avatarImage js-action-profile-avatar" src="https://abs.twimg.com/..." alt="">
What's the easiest way to achieve this in Javascript?
try this
var selectedImages = document.querySelectorAll( "img[src*='abs.twimg.com']" );
check this doc
E[foo*="bar"]- an E element whose foo attribute value contains the substring bar
If you want to select images other than those containing abs.twimg.com, then try using a not selector
var selectedImages = document.querySelectorAll( "img:not([src*='abs.twimg.com'])" );
if by "filter out" you mean remove, then you can do the following:
var nodes = document.getElementsByTagName("img");
// or document.querySelectorAll if you don't care too much for compability
for(var i=0;i<nodes.length;i++){
if(nodes[i].src.indexOf("abs.twimg.com") !== -1){
nodes[i].parentElement.removeChild(nodes[i]); // remove
}
}
img with that domain in src
$('img').filter(function(){ this.src.indexOf('abs.twimg.com')>-1; })