demo/load-event/custom.js
function sanitizeHtml(html){
    var separator = '/';

    if(html.constructor === Object){
        return map(html, function(value){
            var sanitizedHtml = value.split(separator)
                .map(sanitizeHtml)
                .join(separator);
            return sanitizedHtml;
        });
    } else if(html.constructor === Array){
        return html.map(sanitizeHtml);
    }

    var div = document.createElement('div');
    div.appendChild(document.createTextNode(html));
    var sanitizedHtml = div.innerHTML.replace(/&amp;/g, '&');

    if(html != sanitizedHtml){
        return ''; // Blank it
    }

    return sanitizedHtml;
}
function sanitizeHtml(html){
    var separator = '/';

    if(html.constructor === Object){
        return map(html, function(value){
            var sanitizedHtml = value.split(separator)
                .map(sanitizeHtml)
                .join(separator);
            return sanitizedHtml;
        });
    } else if(html.constructor === Array){
        return html.map(sanitizeHtml);
    }

    var div = document.createElement('div');
    div.appendChild(document.createTextNode(html));
    var sanitizedHtml = div.innerHTML.replace(/&amp;/g, '&');

    if(html != sanitizedHtml){
        return ''; // Blank it
    }

    return sanitizedHtml;
}
function sanitizeHtml ( html ) { var separator = '/' ; if ( html . constructor === Object ) { return map ( html , function ( value ) { var sanitizedHtml = value . split ( separator ) . map ( sanitizeHtml ) . join ( separator ) ; return sanitizedHtml ; } ) ; } else if ( html . constructor === Array ) { return html . map ( sanitizeHtml ) ; } var div = document . createElement ( 'div' ) ; div . appendChild ( document . createTextNode ( html ) ) ; var sanitizedHtml = div . innerHTML . replace ( / &amp; / g , '&' ) ; if ( html != sanitizedHtml ) { return '' ; // Blank it } return sanitizedHtml ; }
Use the browser's built-in functionality
to quickly and safely escape a string

@param  string|Array|Object
@return string|Array|Object
Use the browser s built - in functionality to quickly and safely escape a string