Sergey Sergey - 5 months ago 16
HTML Question

document.getElementById doesn't retrieve an element that actually exists

Here is the DOM that clearly contains an input with id=

enter image description here

But when I try to retrieve it from Chrome console using document.getElementById method, it doesn't work:

enter image description here

document.getElementsByName doesn't work either.

Why could this happen? The first screenshot was taken before the second one.

What's interesting is that when I try to run the same code in console a few minutes later, it often works.

Some information that may help:


The input can't be found because it's within an iFrame. You would have to target it with something like this instead:


However, that won't work either because the iFrame is loaded from another domain. So scripts at your site won't be able to interact with content from the iFrame's site due to the same origin policy.