Add custom JavaScript $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#add-custom-javascript">
Add JavaScript files or add code inline by extending the templates.
Add JavaScript files $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#add-javascript-files" x-intersect.margin.0%.0%.-70%.0%="activeSection = '#add-javascript-files'">
To add extra JavaScript files, add your code to a file—for example,
_static/custom.js
and add the following options to your Sphinx configuration:
html_static_path = ["_static"]
html_js_files = ["custom.js"]
See also
Extend templates with inline JavaScript $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#extend-templates-with-inline-javascript" x-intersect.margin.0%.0%.-70%.0%="activeSection = '#extend-templates-with-inline-javascript'">
If you want to add JavaScript inline,
or load additional external scripts,
you can extend the default page
template
and override the extrahead
block:
{% extends "!page.html" %}
{{ super() }}
{% block extrahead %}
<script>
// Add your JavaScript code here
</script>
{% endblock %}