How do I change the text content of a div for a comment validation error message?

My comment form has validation so that when a user tries to post a blank comment, it currently shows the This field is required message under the comment box. How do I change the message content to Please enter your comment.? I'm guessing that the following line of code might do the trick but I don't know how to nest HTML code in my functions.php file.

document.getElementById(comment-error).innerHTML = Please enter your comment.;

Any help would be most appreciated.

Topic wp-comment-query validation html Wordpress

Category Web


if your above Javascript is working fine and you want to insert that into a page.

Kindly add the following code to your functions.php. I have tested this code it's working fine.

function handle_comment_error() {
?>
    <script>
    document.getElementById("comment-error").innerHTML = "Please enter your comment.";
    </script>
<?php
 }add_action('wp_head', 'handle_comment_error');

Let me know if you face any issues.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.