Update: use tagName instead of localName for compatibility with older browsers (e.g IE8 and below).