Bootstrap 4 Tabs with Previous & Next buttons

↘锁芯ラ 提交于 2020-01-23 14:03:24

问题


I'm attempting to create some previous and next buttons within a bootstrap 4 tab snippet, but I'm having trouble with the Jquery. More specifically structuring my trigger event or' the path to my trigger event.

I can't seem to figure out the route properly. I'm fairly inexperienced with Jquery so be gentle. ;P

$(document).ready(function() {
  $('.btnNext').click(function() {
    $('.nav-tabs > .nav-item > .active').next('li').find('a').trigger('click');
  });

  $('.btnPrevious').click(function() {
    $('.nav-tabs > .nav-item > .active').prev('li').find('a').trigger('click');
  });
});

You can find a full snippet of what I'm in the process of building here (JSFiddle);

Many thanks in advance.

-B.


回答1:


You need to get the parent of the active tab and then .next() or .prev(). So, the correct jQuery selectors would be...

  $('.btnNext').click(function() {
    $('.nav-tabs .active').parent().next('li').find('a').trigger('click');
  });

  $('.btnPrevious').click(function() {
    $('.nav-tabs .active').parent().prev('li').find('a').trigger('click');
  });

https://www.codeply.com/go/d7X3s15VCS



来源:https://stackoverflow.com/questions/51655164/bootstrap-4-tabs-with-previous-next-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!