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.