Arjan van der Gaag is a thirtysomething software developer,
historian and all-round geek. This is his blog about Ruby, Rails,
Javascript, Git, CSS, software and the web. See more projects or
follow Arjan at
Github,
Twitter,
LinkedIn or via his feed.

Javascript typeof Nodelist

Written on
05 feb 2010
and tagged
code, javascript

Beware of Javascript’s quirky typeof:

typeof document.getElementsByTagName('p')

This will return 'function', which I did not expect. What is returned is a NodeList, which behaves like an array, identifies itself as a function, but really is neither.

If you want to detect a NodeList you’re better off with feature detection: