I have a use case in which I need to add cells with code dynamically, for this I have used the below code:
%%javascript var code = IPython.notebook.insert_ce