0

I am learning to inject JS script into an HTML. But I don't understand why this code does not work - does not show the alert when loading the window but the script tag is shown properly when inspecting the page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div></div>
    <script>
        const container = document.querySelector("div");
        container.innerHTML = "<script>alert(123)<\/script>";
    </script>
</body>
</html>
Frank
  • 1
  • 1

0 Answers0