<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
</
head
>
<
body
>
<
h2
style
=
"color:green;"
>
GeeksforGeeks
</
h2
>
<
h3
>Dynamically create and remove iframes</
h3
>
<
div
id
=
"display"
></
div
>
<
button
onclick
=
"CreateIframeElement()"
>
CreateIframe
</
button
>
<
button
onclick
=
"RemoveIframeElement()"
>
RemoveIframe
</
button
>
<
script
>
const CreateIframeElement = () => {
// Creating iframe element.
let el = document.createElement("iframe");
// setting the values for the attributes.
el.srcdoc = `<
h1
>.Iframe Element.</
h1
>
<
p
> Hello Geek! <
br
> How are you? </
p
>`;
el.width = "400px";
el.height = "200px";
// Adding the created iframe to div as a child element
document.getElementById("display").appendChild(el);
}
const RemoveIframeElement = () => {
// Remove the last child ( iframe element ) of div.
document.getElementById("display")
.removeChild(document
.getElementById("display").lastChild);
}
</
script
>
</
body
>
</
html
>