user9254958
user9254958

Reputation:

Cannot select a DOM element in Google Chrome Console without inspecting the element first using Chrome Dev Tools

I run into something really strange with Google Chrome Dev Console.

Firstly I reload my page (ctrl + F5), then I launch Google Chrome Dev console (F12) and try to type in

document.getElementById('myElement')

to which Chrome's console responds with:

null

It's weird because I can actually see my element on the page and after I inspected the element using Chrome Dev Tools (right click on the element and choose Inspect) and switched back into the Console tab and typed again: document.getElementById('myElement') I finally got a correct result:

<input type="text" id="myElement" class="urEdf2Txt" autocomplete="off" size="10" maxlength="6" value="1.39" />

Note: I always waited until the page is fully loaded and waited until the element is fully visible before trying the procedure described above.

Upvotes: 1

Views: 892

Answers (1)

Hank X
Hank X

Reputation: 2044

this normally happens on iframe. try to see if the target element is in an iframe in the page.

Upvotes: 2

Related Questions