jQuery - получить ширину опции в списке выбора?

Error: User Rate Limit Exceeded

$('#mySelect').width();

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Ответы на вопрос(4)

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<select id="hack1">
    <option>short option</option>
    <option>loooong looking loooong option</option>
    <option>Longer option but more like the longest</option>
    <option>Medium length selector</option>
</select>

Error: User Rate Limit Exceeded

<select id="hackselect">
    <option></option>
</select>

Error: User Rate Limit Exceeded

#hackselect {
    visibility: hidden;
}

Error: User Rate Limit Exceeded

$('#hack1').change(function(event) {
    $("#hackselect option:first").text($("#hack1 option:selected").text());
    $('#hack1').css('width', $('#hackselect').width() + 6);
});

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

  1. make a new <span> object
  2. set text to the one of the option in question
  3. get computed style values relevant for text width from the selected option
  4. set those measured values to the span
  5. append the span to the body
  6. measure the width of that span
  7. remove the span

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

var getOptionWidth = function(opt) {
    var styleProps = [
        'font-family',
        'font-kerning',
        'font-size',
        'font-stretch',
        'font-style',
        'font-variant',
        'font-variant-ligatures',
        'font-weight',
        'text-transform',
        'letter-spacing',
        'word-spacing',
        'padding-left',
        'padding-right'
    ];
    var o = $('<span>')
        .text($(opt).text());
    for (var i=0; i < styleProps.length; i++) {
        o.css(styleProps[i], $(opt).css(styleProps[i]));
    }
    o.appendTo('body');
    var w = o.width();
    o.remove();
    return w;
}
Решение Вопроса

Error: User Rate Limit Exceeded

 ("#mySelect option:selected").text().length

Error: User Rate Limit Exceeded

$("#mySelect option[value='2']").text().length

Error: User Rate Limit Exceeded

$('#mySelect > option').width();

Error: User Rate Limit Exceeded

Ваш ответ на вопрос