0

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 &nbsp;. However it looks like jQuery, for some reason, is double HTML-encoding this into &amp;nbsp;. How do I prevent this behavior and use a literal &nbsp; (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 += '&nbsp;';
}
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.

2 Answers 2

3

Try using \u00A0 (the non-breaking space character) instead of &nbsp;.

Sign up to request clarification or add additional context in comments.

Comments

2

You can insert the literal non-break space character in your JavaScript scripts with \xA0:

text += '\xA0';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.