[IPython-dev] Regarding Javascript rendering inside IPython notebooks

Matthias BUSSONNIER bussonniermatthias@gmail....
Tue Jun 4 02:54:51 CDT 2013


Use a closure. ie Keep a reference to $mydiv inside the defined reset, or target by #id ( $('#id') ) .
By modifying what you wrote :
>     ...
>     var $mydiv = $("<div/>").attr("id", "#container");
>     var test_var=10;
>     var reset = function(){ test_var=12; $mydiv.text(test_var)}
>     ...

Actually ou probably want something more like

>     // first construct the object you want to modify, 
>     var $myp = $("<p/>").whatever()

>    // use a closure to keep reference.
>     var reset = function(){test_var=12; $myp.text(test_var)}

>    // the rest   
>     var $mydiv = $("<div/>").appen("$p");
append $p to $mydiv , etc ...etc

Keep in mind that those are more JS-centric than Python question, and I, personally
Am far from being a JS expert. 
You will have probably better answer on JS-dev forum if you are looking for JS 
best practice or the exact reason/description of what are clojure in js and what
are the scope of variables.


More information about the IPython-dev mailing list