代碼中的文本大小如下。根據文本大小,我想要更改寬度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
});