也许我只是密集,但我无法弄清楚如何使用id" getThisId"来获取div对象。当"选项2"单击btn-group div:
<div class="panel panel-primary">
<!-- Here's the div element I want to get when "option 2" is clicked -->
<div class="panel-body" id="getThisId">
<div class="itemHeading">sub-heading...</div>
Text...
</div>
<div class="panel-footer">
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">Button text... <span class="caret"></span></button>
<ul class="pull-right dropdown-menu" role="menu">
<li><a href="#">Option 1</a></li>
<li class="divider"></li>
<!-- Get the div with id "getThisId" when this is clicked -->
<li><a href="#" class="confirm_test">Option 2</a></li>
</ul>
</div>
</div>
</div>
</div>
我已经尝试了$(this).parent.prev和$(this).closest等的各种迭代,但似乎没有任何效果。
答案 0 :(得分:1)
因为它是一个ID,所以只需$('#getThisId');
$(this).closest('.panel-footer').prev().find('#getThisId');