Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <input id="thefield" style="width: 300px" value="<div>This is broken HTML<div>missing end tags"><br><input type="button" id="thebutton" value="Go">
  <script>
    (function() {
      document.getElementById("thebutton").onclick = function() {
        var str = document.getElementById("thefield").value;
        display("Before: " + str);
        var e = document.createElement('div');
        e.innerHTML = str; // Parse it
        str = e.innerHTML; // Serialize it properly
        display("After: " + str);
      };
        
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = String(msg).replace(/&/g, "&amp;").replace(/</g, "&lt;");
        document.body.appendChild(p);
      }
    })();
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers