JavaScript function remove <img> by src -


i have problem in javascript , can't figure out:

i have write javascript script (no jquery) remove <img> tags have src="file.jpg" , adds round corners <p> , <div> tags having background image "file.jpg".

i can't work out.

if desired file has different name, not file.jpg example funnyimage.png or change image name (and path before it) if needed:

remove <img> tags file.jpg source:

array.from(document.queryselectorall('img')).foreach(img => {      if(img.src === 'file.jpg') {         img.parentnode.removechild(img);     } }); 

rounded corners:

array.from(document.queryselectorall('p, div')).foreach(node => {     if(node['background-image'] === 'file.jpg') {         node.style['border-radius'] = '10px'; // example 10px     } }); 

or (much more intelligent , efficient way):

const style = document.createelement('style'); style.textcontent = 'p[background-image="file.jpg"], div[background-image="file.jpg"] { border-radius: 20px; }'; document.head.appendchild(style); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -