It is hard to say, as we don't know what currentNode and dojo.doc are. But I put a dime on a bet. I guess you try to create/remove/replace an element from another document (an iframe, a pop-up, an opener or a parent). Make sure you use the correct and full reference of the document you are working with.
For instance, if your code is written in an iframe, but you need to do something in the DOM of its parent, make sure you work in the correct document, that means the parent: