javascript - Toggle to hide cell output in the HTML version
问题描述
The following code displays a link that shows/hides the output of the next cell:
from IPython.display import HTML
HTML('''<script>
function code_toggle_next() {
$('div.cell.code_cell.rendered.selected').next().find('div.output').toggle();
}
$( document ).ready(code_toggle_next);
</script>
<a href="javascript:code_toggle_next()"> To show/hide next the output of the next cell, click here </a>.''')
However it doesn't seem to work once the notebook has been exported to HTML: the output of the next cell is displayed, and clicking on the link doesn't do anything. Any suggestion on how to fix this?
解决方案
When you open the HTML file and select Inspect element or DEV tools depending on your browser, you'll see that the cell misses the class selected
, so the first selector returns an empty result. I tried and removing that class fixes the behaviour.
However, it returns all cells instead, so if you take .next().find('div.output')
then it will apply to all but the very first cell. It's probably better to use the onclick
attribute. This way, you can pass the cell you clicked on as an argument to the function (see the docs) and still toggle only the following cell. Have a look:
from IPython.display import HTML
HTML('''<script>
function toggle_next(event) {
$(event.target).closest('div.code_cell').next().find('div.output').toggle();
}
</script>
<a onclick="toggle_next(event)"> To show/hide next the output of the next cell, click here </a>.''')
推荐阅读
- tcpdf - TCPDF 生成超大格式 (HUGE) 页面布局
- python-3.x - pymysql 停止工作:NameError: name 'byte2int' is not defined
- sap - 业务对象:替换 sap Bo Universe 中所有未更改的架构名称
- java - Artifactory 未能初始化:上下文为空
- android - 我正在开发一个 android 应用程序,如何通过点击地址进入谷歌地图?使用 Sqlite 的一些代码在这里
- angular - 如何托管多个 Angular 应用程序,使用 nginx 容器进行子域化
- android - EGL 错误:0x3003,相机设备遇到严重错误(Camera2 Api)
- angular - Angular - controlValueAccessor 方法 writeValue() 未被调用
- angular - 在 wwwroot 以外的目录中的 .Net Core 中运行 Angular App
- amazon-web-services - 选择正确的 EC2 实例类型?