Skip to content

Instantly share code, notes, and snippets.

@manabuyasuda
Created February 4, 2016 10:32
Show Gist options
  • Save manabuyasuda/bcf72f248f609636200b to your computer and use it in GitHub Desktop.
Save manabuyasuda/bcf72f248f609636200b to your computer and use it in GitHub Desktop.
// タブリスト
// `.index(this)`でクリックされた`li`のインデックスを取得して変数に格納。
// `.eq()`でインデックスを渡す。
// `return false;`でアンカータグを無効化する。
$(function(){
var $tabList = $('.tabList').find('li');
var $tabBody = $('.tabBody').find('li');
var state = 'is-active';
$tabList.click(function() {
var $index = $tabList.index(this);
$tabList.removeClass(state);
$tabBody.removeClass(state);
$(this).addClass(state);
$tabBody.eq($index).addClass(state);
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment