How do I use jQuery in page.html.twig? In Drupal 7 I used some JavaScript that required jQuery in the page.tpl.php file using the following code.

&lt;script type="text/javascript"&gt;
    (function($) {
    $( ".mobile-menu-button" ).click(function() {
    $(".navigation").toggleClass( "visible" );
    $(this).toggleClass( "active" );
});
    })(jQuery);
&lt;/script&gt;


Hod do I do this in Drupal 8? I have tried many ways of adding this code (with and without the jQuery argument above) in page.html.twig without success. I can see the code in the page source, but it fails to work.
You need to write JavaScript in a js file in your theme, declare a library within your theme and attach it globally or inside of a theme page attachments hook. You also need to depend on jquery from core in your library yaml definition as well.

See: https://www.drupal.org/docs/8/theming-drupal-8/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme