jquery遍历到父级以更改css
我在一个页面上有多个下拉列表: HTMLjquery遍历到父级以更改css,jquery,css,closest,Jquery,Css,Closest,我在一个页面上有多个下拉列表: HTML <div class="select-full"> <select id="activitylevel" class="input_select step2-ddl c2-sb-enabled"> <option selected="selected" value="-1">-- please select --</option> <option value="
<div class="select-full">
<select id="activitylevel" class="input_select step2-ddl c2-sb-enabled">
<option selected="selected" value="-1">-- please select --</option>
<option value="1">Step 1 </option>
<option value="3">Step 2</option>
<option value="4">Step 3</option>
</select>
<div class="c2-sb-wrap" tabindex="0">
<div class="c2-sb-inner-wrap"></div>
</div>
</div>
使用.find()
而不是.nextAll()
比如:
作为补充说明,我建议切换类而不是直接更改CSS属性,因为它更精简、更干净。是否希望在页面加载时应用此边框?还是希望每次选择某个选项时都对其进行更改?
$('.step2-ddl').each(function() {
if ($(this).val() == '-1') {
$(this).closest('.select-full').nextAll('.c2-sb-inner-wrap').css('border-color', '#f86556').css('border-style', 'solid');
}
else {
$(this).closest('.select-full').nextAll('.c2-sb-inner-wrap').css('border-style', 'none');
}
});
$(this).closest('.select-full').find('.c2-sb-inner-wrap')
.css('border-color', '#f86556').css('border-style', 'solid');