var replace = (function (){
var ruleReplacable = {
'<' : "<",
'>' : ">",
'"' : """
};
return function ( text ) {
return ("" + text).replace(/(<|>|")/g, function( match ){ return ruleReplacable[match] || match; })
};
})();
alert( replace('<div class="test">test</div>') );
И дальше по аналогии...