Ajax load more posts button

1) You should really use a separate JS file.
2) Check this guide: https://premium.wpmudev.org/blog/using-ajax-with-wordpress/

tech