In [1]:
from IPython.display import HTML

In [2]:
%%writefile jquery_slide_toggle.html

<script>
$(document).ready(function(){
    $("#flip").click(function(){
        $("#panel").slideToggle("fast");
    });
});
</script>


Overwriting jquery_slide_toggle.html

When the document is ready (loaded and the DOM constrcuted), jQuery will register the click callback on the elements with the #flip id.


In [3]:
%%writefile jquery_slide_toggle.html -a

<style> 
#panel, #flip {
    padding: 5px;
    text-align: center;
    background-color: #e5eecc;
    border: solid 1px #c3c3c3;
}

#panel {
    padding: 50px;
    display: none;
}
</style>


Appending to jquery_slide_toggle.html

In [4]:
%%writefile jquery_slide_toggle.html -a

<div id="flip">Click to slide the panel down or up</div>
<div id="panel">Hello world!</div>


Appending to jquery_slide_toggle.html

In [5]:
HTML('./jquery_slide_toggle.html')


Out[5]:
Click to slide the panel down or up
Hello world!

Note

I was first typing the entire html code in one cell and executing it.

But later I need to make notes, so I came up with the %%writefile cell magic way to organize the html code.


In [6]:
%%html 

<script>
$(document).ready(function(){
    $("#flip0").click(function(){
        $("#panel0").slideToggle("fast");
    });
});
</script>

<style> 
#panel0, #flip0 {
    padding: 5px;
    text-align: center;
    background-color: #e5eecc;
    border: solid 1px #c3c3c3;
}

#panel0 {
    padding: 50px;
    display: none;
}
</style>
 
<div id="flip0">Click to slide the panel down or up</div>
<div id="panel0">Hello world!</div>


Click to slide the panel down or up
Hello world!