Just for information, you can do wwLib.getFrontDocument() rather than just document to be sure to always target the app document (iframe in the editor or the published app).
Just for information, you can do wwLib.getFrontDocument() rather than just document to be sure to always target the app document (iframe in the editor or the published app).