skip to Main Content

I’ having a little trouble figuring this out. Is there a way to remove an image from a site page using Javascript if the image does not have an ID? Here’s the on the site page with the link URL:

<img src="https://storage.googleapis.com/icons/markup.png" alt="Mark Up Icon" width="40" height="40" data-decorative="true">

I’ve tried the following but it doesn’t seem to work:

$("img[src='https://storage.googleapis.com/icons/markup.png']").remove();

2

Answers


  1. Chosen as BEST ANSWER

    Thank you all! After a lot of testing, I ended up using Javascript and adding a 0.15 second time delay. It looks like the javascript was executing before the html was loaded. Not the most ideal solution, but it ended up working.

    // Delay in milliseconds before executing the removeImages function
    var delay = 150; // 0.15 seconds
    
    // Set a timeout to delay the execution
    setTimeout(removeImages, delay); 
    
    });
    

  2. Your attribute selector has a problem. Try with double quotes instead of single quotes:

    $('img[src="https://storage.googleapis.com/icons/markup.png"]').remove();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search