jQuery script not working after via AJAX submitted comment

by jackennils   Last Updated July 25, 2018 07:08 AM

I'm using the standard WP comments together with WP Ajaxifiy Comments. So when someone leaves a comment, it is added via AJAX without reloading the page.

Since the comment form is pretty "long" in terms of its height I use a little jQuery script. First of all, except for the textarea (the comment itself), all other fields are set to display none by default to make it shorter. Then when someone wants to leave a comment and clicks/taps into the textarea, the script shows the other fields. That allows me to save space especially in terms of not having to scroll to much unnecessarily.

This is the script:

jQuery(document).ready(function( $ ) {
        $('.comment-form-comment').click(function() {

Now to the problem: It only works once. After I submitted a comment and it was added via AJAX, clicking into the textarea does not have any effect anymore. I need to manually reload (i.e. by pressing F5) the page for the script to work again.

How can I fix this? Can someone assist please? Thanks!

You can try it out here (feel free to sumbmit dummy comments, I'll delete them later, no problem): https://mydivision.net/2018/06/kommt-the-division-2-mit-8-spieler-raids/

Related Questions

Jquery not appearing on homepage

Updated January 22, 2018 07:08 AM