Awesome ampersands with jQuery

$(document).ready(function() {
    $("*:contains('&')", document.body)
        .contents()
        .each(
            function() {
                if( this.nodeType == 3 ) {
                    $(this)
                        .replaceWith( this
                            .nodeValue
                            .replace( /&/g, "<span class='amp'>&</span>" )
                        );
                }
            }
        );
});
Snippet : Source

Leave a Reply