Reputation: 7867
Is it a bug? This select works:
<select id="select_advsels" name="pixel_advsels" multiple>
<option>All</option><option>Mobvista (TS-126)</option>
</select>
jQuery('#select_advsels').val(['Mobvista (TS-126)']);
When two words in OPTION are separated by more than one space, jQuery fails to select:
<select id="select_advsels" name="pixel_advsels" multiple>
<option>All</option><option>Mobvista (TS-126)</option>
</select>
jQuery('#select_advsels').val(['Mobvista (TS-126)']);
Upvotes: 1
Views: 432
Reputation: 388316
While html is rendered, it replaces the continues spaces with a single one :
jQuery('#select_advsels option').each(function(){
console.log(this.value.replace(' ', '-'));
})
Demo: Fiddle
Refer this
HTML treats whitespace characters (spaces, tabs, and newlines) differently from ordinary characters. In general, a single whitespace character--including newlines--or a sequence of whitespace characters are treated as a single space and leading/trailing whitespace is eliminated. This is known as 'collapsing whitespace'. Therefore the following two paragraphs are treated as if they were identical
Upvotes: 4
Reputation: 38345
As has already been explained, the browser collapses multiple continuous whitespace characters down to a single space. If you absolutely need to preserve the double spaces then use explicit value
attributes when declaring your <option>
tags:
<option value="Mobvista (TS-126)">Mobvista (TS-126)</option>
The value displayed to the user will only have a single space, but the value sent when the form is submitted or matched when using JavaScript will retain the multiple spaces.
Upvotes: 1