I think the "thisNode" should be "element" (you can name it "newNode" to avoid confusion). The whole logic of this method needs to be re-examined.