JSFiddle - React, Tailwind, and code Playground

by Alphonsio

HTML

<input id="input" type="text" value='& < >  \ " /  ` ='>
<div id="output"></div>

CSS

body {
  background-color: #eee;
}

JavaScript

function escapeHTML(str) {
	const div = document.createElement('div');
  div.textContent = str;
  return div.innerHTML;
}

let input = document.getElementById("input");
let output = document.getElementById('output');

function update() {
	output.textContent = escapeHTML(input.value);
}

input.addEventListener("input", update)

update();