Sometimes, we want to pick element inside iframe using document.getElementById with JavaScript.
In this article, we’ll look at how to pick element inside iframe using document.getElementById with JavaScript.
How to pick element inside iframe using document.getElementById with JavaScript?
To pick element inside iframe using document.getElementById with JavaScript, we can use the contentWindow property.
For instance, we write
const el = document
.getElementById("myframe1")
.contentWindow.document.getElementById("x");
to select the iframe with getElementById.
Then we use contentWindow.document.getElementById to select the element with ID x in the iframe.
Conclusion
To pick element inside iframe using document.getElementById with JavaScript, we can use the contentWindow property.