2

I'm getting null when trying to find <body> element with querySelector() on document object after compiling to javascript. Here's the Dart code:

void main() {
  print(document.querySelector('body')); // => null
}

This also produces a range error:

document.getElementsByTagName('body')[0] // => Range error, obviously the List is empty

The dart code works just fine in Dartium though.

orion3
  • 9,797
  • 14
  • 67
  • 93

2 Answers2

3

Figured it out. I included the script in the <head> section, and should've done it after all the contents inside <body>.

orion3
  • 9,797
  • 14
  • 67
  • 93
  • one should use `defer` for scripts that need to wait until the document is parsed. Unfortunately, `pub build` does not transform deferred dart scripts. Things that make me go hmm – Draško Kokić Jul 04 '15 at 17:34
1

Weird, but you don't need querySelector() for the body element. Just use document.body

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567