javascript - jQuery : how to show the next div and hide the present one

标签 javascript jquery jquery-ui

我需要隐藏当前的 div 并显示下一个 hide 这是我的代码

$(document).ready(function() {
  $('#next').click(function() {
    $(this).next().next().children("div").hide();
    $(this).next().next().children("div").show();
  });
});
#div2,
#div3 {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<button id="prev">Prev</button>
<button id="next">Next</button>
<hr />
<div id="main">
  <div id="div1">Div 1</div>
  <div id="div2">Div 2</div>
  <div id="div3">Div 3</div>
</div>

DEMO

最佳答案

this . 使用 css 类处理开始/结束,保持 js 简单。

关于javascript - jQuery : how to show the next div and hide the present one,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9978491/

相关文章:

javascript - Foundation 6 网格编程列删除

javascript - 如何将 jquery ui '.droppable' 与 jquery '.on' 函数一起使用?

javascript - vue - 普通链接如何像 <route-link> 一样工作?

javascript - 单元测试使用 Karma 和 Jasmine 使用react

javascript - 在 jQuery 中为 id 添加一个数字,以便在 jQuery/JavaScript 中使用

Jquery 拖放排序从列表到表格单元格不起作用

javascript - 如何在同一页面上加载多个版本的 jQuery 插件?

javascript - Angularjs 表单问题。表格不可见

jquery - 多个选择会禁用彼此的选项

javascript - 无法显示 fancyBox 标题