【发布时间】:2016-01-19 10:39:35
【问题描述】:
首先我已经解决了一些与我的标题相同的问题,例如this 等,但没有一个解决我的问题。
HTML部分-
<tr id="row_question_container">
<td valign="top" colspan="2">
<div id="at_test_area-1" class="at_test_area">
<div id="at_questions_container">
<div id="1" class="question_block completed unmarked" style="display: none;">
<!-- Question / Option / Settings etc in nested tables are here -->
</div>
<div id="2" class="question_block completed marked">
<!-- Question / Option / Settings etc in nested tables are here -->
</div>
<div id="3" class="question_block incomplete unmarked" style="display: none">
<!-- Question / Option / Settings etc in nested tables are here -->
</div>
<div id="4" class="question_block incomplete unmarked" style="display: none">
<!-- Question / Option / Settings etc in nested tables are here -->
</div>
</div>
</div>
</td>
</tr>
我想要实现的是获得具有类incomplete 或marked 的div 的下一个/壁橱id(使用下一个和上一个按钮导航)。在阅读了类似的问题后,我尝试关注 jQuery,但它返回了undefined
var marked_question = $('#at_questions_container').next('.marked').attr('id');
alert(marked_question);
【问题讨论】:
-
问题是你在容器级别工作,而
next()工作在兄弟姐妹上,所以你应该查看当前可见的子元素并在上面使用next()。