jQuery code not working when included in functions.php

When using a child theme, get_template_directory_uri() returns the URI of the parent theme, you want to swap that for get_stylesheet_directory_uri(), which will load assets from your child theme directory.