The epub 3.0 spec forbids scripts from changing the DOM of the document, so this will not be possible. Here's the relevant bit:
It must not allow a container-constrained script to modify the DOM of the parent Content Document or other contents in the EPUB Publication, and must not allow it to manipulate the size of its containing rectangle. (Note: Even if a script is not container-constrained, the Reading System may impose restrictions on modifications (see also the dom-manipulation feature).)
This is required for security purposes. It sounds like in order to do what you're talking about, you'll need an app rather than an ebook.
There's no support for that currently. EPUB is intended to be a one-way delivery system, that is why it's contents are packaged in a predictable format with strict specifications. In order to alter the contents of an Epub you must unzip the file into its constituent parts.