Take DOM manipulation out of tag code

Change-Id: Ie2fb3e3fe2bdbcaf08e38e9da7a5c7ee778cca15