Awesome ampersands with jQuery

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

    Leave a Reply