jQuery-查找下一个Div [英] jQuery - Finding next Div
本文介绍了jQuery-查找下一个Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在输入按钮后找到下一个div并将其切换.
I am trying to find the next div after an input button and toggle it.
我在做什么错了?
JS:
$(".showNextExperience").click(function() {
$(".experience").show();
});
HTML:
<input class="showNextExperience" >
<div class="experience">Experience 1</div>
<input class="showNextExperience">
<div class="experience">Experience 2</div>
<input class="showNextExperience">
<div class="experience">Experience 3</div>
<input class="showNextExperience" >
<div class="experience">Experience 4</div>
好的,这不起作用---
Okay, this DOES NOT work ---
$(".showExperience").click(function() {
$(this).next(".experience").toggle();
});
<table class="data">
<tr class="tableHead">
<td></td>
<td width="50" align="right"><input type="button" class="showExperience" value="show"></td>
</tr>
</table>
<div class="experience">2</div>
当我将输入按钮移到DIV上方时,它就可以正常工作.
When I move the input button just above the DIV it works just fine.
$(".showExperience").click(function() {
$(this).next(".experience").toggle();
});
<input type="button" class="showExperience" value="show">
<div class="experience">2</div>
你能解释一下吗?
推荐答案
简单地:
$(".showNextExperience").click(function() {
$(this).next(".experience").toggle();
});
请参阅:
- http://api.jquery.com/toggle/
- http://api.jquery.com/next/
这篇关于jQuery-查找下一个Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文