Simple Tool: LT and GT Replace

This page replaces “<" and ">” with “&lt;” and “&gt;”. I found myself doing it in my blog posts and thought it would be a good, simple exercise to do in my portfolio space and could be used by myself or others in the future.

Enter code here:


Updated code will display here:

The jQuery code itself doing the replacing:

<script>
(function($) {
	$("#btnReplace").click(function() {
		var str = $("#PutCodeHere").val();
		str = str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
		str = str.replace( /\r?\n/g, "\r\n" );
		$("#Replaced").text(str);
	});
})( jQuery );
</script>

Source for figuring out what I needed found here:
https://stackoverflow.com/questions/20964811/replace-amp-to-lt-to-and-gt-to-gt-in-javascript