[英]I can not select the right div using “.child” or “.next” in jQuery
[英]How can I select the next div using jQuery?
当涉及到 jQuery 时,我是一个菜鸟,我正在尝试使用 next() 选择器来 select 下一个元素,但在让它工作时遇到了一些麻烦!
我要做的是在用户完成对 ui slider 的选择后激活 slideDown()。 这是我的代码:
$('.slider').slider({ stop: function(event, ui) { $(this).nextAll('.secondq:first').slideDown('slow') } });
麻烦的是,这根本行不通。 只有当我将“secondq”问题放在 ui slider 的父 div 中时,它才会起作用。 这是我的 HTML:
<div class="option">
<h2 align="left">How high is your ceiling from the floor?</h2>
<input type="text" align="right" name="bonus" class="value" disabled="disabled" />
<div class="slidewrap">
<div class="sliderFt slider"></div>
</div>
</div>
<!-- End Option -->
<div class="option">
<h2 align="left">How many windows do you have?</h2>
<input type="text" align="right" name="bonus" class="value" disabled="disabled" />
<div class="slidewrap">
<div class="sliderWinDoor slider"></div>
</div>
<div class="secondq" style="display:none;">
<h2>What type of material are your windows made of?</h2>
<div class="radiocont">
<label>Wood</label>
<input type="radio" class="styled" value="wood" name="windowtype" />
</div>
<div class="radiocont">
<label>Metal</label>
<input type="radio" class="styled" value="metal" name="windowtype" />
</div>
<div class="radiocont">
<label>PVC</label>
<input type="radio" class="styled" value="pvc" name="windowtype" />
</div>
</div>
</div>
nextAll
只得到兄弟姐妹。 根据您的 HTML 结构,您可以执行以下操作:
$(this).parent().next()
为了使其更独立于结构,您还可以执行以下操作:
$(this).closest('.slidewrap').nextAll('.secondq:first')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.