Chrome wraps font families having multiple words with single quotes. So the value for font-family returned in Chrome is: 'Times New Roman'
which does not match the value in the select list Times New Roman
.
Considering all these browser variations, I think the best solution is to split apart the family names by comma, trim the single quote (if any) around each font name, and join them later. Use this sanitized value inside the select list.
$('#selectable1 span').live('mousedown', function() {
var fontFamily = $(this).css('font-family');
var fonts = fontFamily.split(',');
var sanitizedFonts = $.map(fonts, function(name) {
// trim single quotes around font name (if any) for Chrome/Safari
// trim double quotes around font name (if any) for Firefox
return name.trim().replace(/^['"]|['"]$/g, '');
});
$('#family').val(sanitizedFonts.join(', '));
});
See an example. The select list had to be changed to follow this consistent naming scheme for values:
fontName[, fontName]
This heavily relies on the fact that a font-name will not contain any commas, quoted or unquoted.