我试图弄清楚为什么这不起作用。我有一个<rvml:fill class=rvml firebug-1432221487827="1566" rotate = "t" src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAEJJREFUeNpiPHnyOAMUZANxPRA/ZGFAAFkgFgVhkGAcEPMDMRsQ7wTiHyDBhVCVE4DYA8RgAuLXQPwNiF/CzAEIMABgqgriagn8AQAAAABJRU5ErkJggg==" type = "tile" position = "13861519f,3859415f"></rvml:fill>
,如果它有一个或多个div
个span
类的孩子,我想要切换。
请参阅JSFiddle
.reqiredError
<div class="more-content" style="display:none;">
<div class="col-xs-5 form-group">
<label for="dua-status">
Status:
<span class="required">*</span>
<span class="requiredError">Required Field</span>
</label>
<select id="dua-status">
<option>Open</option>
</select>
</div>
</div>
答案 0 :(得分:0)
您不需要if
声明。
相反,使用:has()使用选择器定位它们。这样做的好处是您不必导航到父级,因为上下文将是具有那些跨度的父div
$(document).ready(function() {
$('div.more-content:has(.requiredError)').fadeIn(0);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="more-content" style="display:none;">
<div class="col-xs-5 form-group">
<label for="dua-status">Status: <span class="required">*</span> <span class="requiredError">Required Field</span>
</label>
<select id="dua-status">
<option>Open</option>
</select>
</div>
</div>
答案 1 :(得分:0)
你可以找到目标元素然后使用.closest()找到目标祖先元素
$(document).ready(function() {
$('.requiredError').closest('.more-content').fadeIn(0);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="more-content" style="display:none;">
<div class="col-xs-5 form-group">
<label for="dua-status">Status: <span class="required">*</span> <span class="requiredError">Required Field</span>
</label>
<select id="dua-status">
<option>Open</option>
</select>
</div>
</div>
&#13;