I am trying to convert an unordered list into a <select>
box for people with small resolutions, indenting the text depending on the level in the list. To do this, I prepend the string with
. However it looks like jQuery, for some reason, is double HTML-encoding this into &nbsp;
. How do I prevent this behavior and use a literal
(i.e. so that a non-breaking space character is shown to the browser):
var text = '';
var i;
for (i = 0; i < level; i++) {
text += ' ';
}
text += el.text();
if (el.hasClass('noclick')) {
$('<optgroup />', {
'label' : text
}).appendTo('#menu select');
}
else {
$('<option />', {
'value' : el.attr('href'),
'text' : text
}).appendTo('#menu select');
}
Here's my jsFiddle.
Try using \u00A0
(the non-breaking space character) instead of
.