fix bugs caused by performing DOM methods on elements not attached to DOM