Aug 1, 2010 An explanation of when to use encoded ampersands (&) in HTML and Javascript and when not to encode them.

8192

function htmlEncode( html ) { return document.createElement( 'a' ).appendChild( document.createTextNode( html ) ).parentNode.innerHTML; }; function htmlDecode( html ) { var a = document.createElement( 'a' ); a.innerHTML = html; return a.textContent; }; document.getElementById( 'text' ).value = htmlEncode( document.getElementById( 'hidden' ).value ); //sanity check var html = '

& hello
'; document.getElementById( 'same' ).textContent = 'html === htmlDecode( htmlEncode( html

Forum » HTML / CSS / JavaScript » Ajax visar ej åäö ');d=b('