How to remove empty iframe with jquery?

Member

by dana , in category: HTML & CSS , 2 months ago

How to remove empty iframe with jquery?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 2 months ago

@dana 

You can remove an empty iframe using jQuery by selecting the empty iframe element and then calling the remove() method on it. Here is an example code snippet:

1
2
3
4
5
// Select the empty iframe element
var iframe = $('iframe:empty');

// Remove the empty iframe element
iframe.remove();


This code will select all empty iframe elements on the page and then remove them from the DOM. Make sure to place this code within a document.ready function to ensure that the iframe elements are present in the DOM before attempting to remove them.