I'm attempting to make a site with an example of what XSS would look like, so in this I take user input and set a paragraph element's innerHTML to the user input but the script isn't running. However the script tag is present within the span. Anyone know why?
input in text box: <script>alert()</script>
code:
<!doctype html>
<html lang="en">
<head>
<title>XSS example</title>
</head>
<body>
<input type="text" id="inputBox"/>
<button id="displayButton">submit</button>
<span id="inputDisplay"></span>
<script>
const textInput = document.getElementById("inputBox");
const inputDisplay = document.getElementById("inputDisplay");
const displayButton = document.getElementById("displayButton");
displayButton.onclick = event => {
inputDisplay.innerHTML = textInput.value;
textInput.value = "";
}
</script>
</body>
</html>