leeand00
leeand00

Reputation: 26392

Chrome returns null when using getElementById() in the console until I inspect an element?

I use CTRL+SHIFT+I to open the JS Console on a page I am working on (not one I am actively developing) in Chrome Version 86.0.4240.111, I immediately start to type document.getElementById('Clear All') and I get back null

But after I click the Elements tab, and inspect the element with the id="Clear All" attribute, running the same function (document.getElementById('Clear All')) returns the element.

Does this have something to do with there being a space in the id attribute? Is there a way to preload the DOM so that I can pull the Clear All element without inspecting the page first?

Additionally of note, this page has <frameset>s and the element I want to access is inside one.

Considering this is a newer product, I really can't believe they use <frameset>s.

Upvotes: 2

Views: 517

Answers (1)

Bruno Melo
Bruno Melo

Reputation: 89

Don't use space on ID ... try id="clear-all" on element and on javascript-> document.getElementById("clear-all")

Upvotes: 1

Related Questions