I'm attempting to remove an image from an embedded iframe (inline iframe). While it works sometimes, sometimes it failes with an error. I am running this code on Chrome. This behaviour is strange. I have tried this on a few sites and I am unable to find any reason for this.
I would like to know why it fails sometimes and does not sometimes with all parameters the same (I'm simply executing this in the console). Secondly, if possible is there an alternative solution?
$("#content_ifr").contents().find("img").remove();
Error message that occurs sometimes:
Uncaught TypeError: Cannot read property 'contents' of null
If it helps, I'm attempting to remove images and extra content from the WordPress page editor (Classic) using JavaScript.