views:

57

answers:

4

If I just put in XUL file

<label value="&#176;C"/> 

it works fine. However, I need to assing &#176; value to that label element and it doesn't show degree symbol, instead literal value.

UPD sorry guys, I just missed couple words here - it doesn't work from within javascript - if I assign mylablel.value = degree + "&#176;" - this will show literal value.

It does show degree symbol only if I put above manually in XUL file.

+1  A: 

This way it will not work ,can you convert it to be like this

<label>&#176;C</label> 
Kronass
Not necessary; it's possible to set it but you have to use Javascript syntax for the special character, not XML syntax.
Pointy
This is XUL, not HTML.
Ms2ger
A: 

I don't know about XUL, but if you need the value itself (and not its rendered HTML representation) in a HTML element you would have to escape the ampersand:

&amp;#176;C
Pekka
sorry, no solution mentioned here so far worked. please see my update
Michael
+2  A: 

What happens when you use a JavaScript escape, like "\u00B0C", instead of "&#176;C"?

Or when using mylabel.innerHTML instead of mylabel.value? (According to MDC, this should be possible.)

EDIT: you can convert those entities to JavaScript escapes using the Unicode Code Converter.

Marcel Korpel
@Marcel: yes, first one worked! Thanks!!
Michael
+3  A: 

This makes sense to me. When you express the entity in an attribute value within XML markup, the XML parser interpolates the entity reference and then sets the label value to the result. From Javascript, however, there's no XML parser to do that work for you, and in fact life would be pretty nasty if there were! Note that when you set the value attribute (from Javascript) of an <input type='text'> element, you don't have to worry about having to escape XML entities (or even angle brackets, for that matter). However, you do have to worry about XML entities when you're setting the "value" attribute within XML markup.

Another way to think about it is this: XML entity notation is XML syntax, not Javascript syntax. In Javascript, you can produce special characters using 16-bit Unicode escape sequences, which look like \u followed by a four-digit hex constant. As noted in Marcel Korpel's answer, if you know what Unicode value is produced by the XML entity, then you should be able to use that directly from Javascript. In this case, you could use "\u00B0".

Pointy
You meant ‘16-bit’? ;)
Marcel Korpel
ha ha yes! Thanks
Pointy