Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
var text = "<a href=\"#\" id='foo'>föo</a>";
var encodeHTML = function(str){
    str = str.split("");
    var i = str.length,
        ret = [];
    while (i--) {
        var iC = str[i].charCodeAt();
        ret[i] = (iC < 65 || iC > 127 || (iC>90 && iC<97)) ? '&#'+iC+';' : str[i];
    }
    return ret.join("");
};
document.body.innerHTML += encodeHTML(text);
var html = text.replace(/[<&>'"#]/g, function(s) {
    return {'<':'&lt;', '>':'&gt;', '&':'&amp;', '"':'&quot;', "'":'&#039;', '#':'&#035;'}[s];
});
document.body.innerHTML += html;
text = text.replace(/[<&>'"]/g, function(c) {
    return '&#' + c.charCodeAt() + ';';
});
document.body.innerHTML += text;
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers