Categories
JavaScript Answers

How to pick element inside iframe using document.getElementById with JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.