JavaScript on page



I’m creating a complex website and I’m using in general jQuery. On some pages (markdown files) I would like to add a document.ready function . How can I put some JavaScript code inside the markdown file?
My first idea is to create a page property, which is put inside the header if it is set. But is there any buildin functionality to put page specialized JavaScript code to a page?


[SOLVED] Javascript in shortcodes



Thanks for that, but I understand it in this case, that I can define a JavaScript file and include it by a block structure, but in my case I would like to add “inline JavaScript code”.


You can include regular HTML in you Markdown files. So a <script> tag should work. Maybe it can happen that Go templates escape them for security reasons (unless Hugo trusts the user and marks it as safe by default).




Yes the problem are the quotes. I have got this code e.g.

$(document).ready(function() {
     $("#animatefsm").click( {
 } );

And the double-quotes within the jQuery call are escaped. How can I avoid the escaping within the markdown file of this block?



… just an idea, … not sure/didn’t try - about that :

{{ `<script>
$(document).ready(function() {
$("#animatefsm").click( {
} );
</script>` | safeJS }}

note: use backticks not apostrophes