docmattman
07-31-2006, 05:45 AM
I'm having a problem when I want to do something like this in js:
var someCode = "You & I";
document.getElementById('someElement').innerHTML = someCode;
My problem is with the ampersand. When it is displayed in the browser, it actually looks fine, but it's not what I want/need. It actually sets the innerHTML of the element to "You & I". The ampersand is getting encoded automatically (which I don't want). This would not be much of a concern if all I was doing was setting the innerHTML, but I will also need to access it later on in my script. Later on I will do something like this:
alert(document.getElementById('someElement').innerHTML);
I actually will be doing much more than just the alert, but I'm just demonstrating... Anyway, the problem is that what I originally intended to put inside the "someElement" is not actually what happened. Is there a way that I can prevent the conversion of an ampersand symbol ( & ) to the ampersand entity ( & )?
var someCode = "You & I";
document.getElementById('someElement').innerHTML = someCode;
My problem is with the ampersand. When it is displayed in the browser, it actually looks fine, but it's not what I want/need. It actually sets the innerHTML of the element to "You & I". The ampersand is getting encoded automatically (which I don't want). This would not be much of a concern if all I was doing was setting the innerHTML, but I will also need to access it later on in my script. Later on I will do something like this:
alert(document.getElementById('someElement').innerHTML);
I actually will be doing much more than just the alert, but I'm just demonstrating... Anyway, the problem is that what I originally intended to put inside the "someElement" is not actually what happened. Is there a way that I can prevent the conversion of an ampersand symbol ( & ) to the ampersand entity ( & )?