代码中的文本大小如下。根据文本大小,我想要更改宽度DIV
。就像如果选择选项的最大文本长度大于100则父div的宽度更改为240像素,改变选择标签的宽度。选择风格按在选择下拉标签
<div class="products">
<select>
<option>Test 1</option>
<option>Test 2</option>
<option>Test 3</option>
<option>Test Test Test Test Test </option>
</select>
</div>
的javaScript我试图
jQuery(document).ready(function(){
jQuery('.products select option').each(function(){
var maxLength = jQuery(this).val().length;
console.log(maxLength);
});
// if max length is greater than 50 then increase the width of the div 250px
});