Back jQuery

How to Add Fancy JQuery Live Comment Preview to Comment Textarea without Plugin

WRITTEN BY ON 21 Mar 2011
21,545 VIEWS • SHARES
9 comments

The comment live preview feature helps the comment writer to see what they are writing in the comment form as they write. This feature works well to help prevent errors in spelling and grammar by giving the user a chance to see what they are writing before they post their comment.

Javascript

put the code in the header.php, right before end of head tag. You can read for more explanation here: http://www.dynamicwp.net/articles-and-tutorials/how-to-add-live-comment-preview-to-comment-textarea-without-plugin/

<script type="text/javascript">

jQuery(document).ready(function(){

	jQuery("").add("<h3 id='preview-title'>Comment Preview</h3><div id='comment-preview'></div>").appendTo(document.body);
	jQuery("#comment-preview, #preview-title").insertAfter("#comment");

	var $comment = '';
	jQuery('#comment').keyup(function() {
		$comment = jQuery(this).val();
		$comment = $comment.replace(/

+/g, '<br /><br />').replace(/
/g, "<br />");
		jQuery('#comment-preview').html( $comment );
	});

});

</script>

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.

9 comments
maiiiiiiiii 12 years ago
yeeeeeeeeeeeeeeeeees
Reply
joy 10 years ago
nice :D
Reply
tanja 10 years ago
great!
Reply