3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQuery tab切りかえ

3
Last updated at Posted at 2016-02-27

tab切りかえ

jsめも
each使ったらthisもつかう

js
$(function(){
	$("#price-tab li").click(function(){

		var tab_img = $(this).parent().find("img");
		var _this_img = $(this).find("img");
			// tab_img.attr("src",tab_img.attr("src").replace("-on.", "-off."));
		tab_img.each(function(){
			$(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
		});
			_this_img.attr("src", _this_img.attr("src").replace("-off.", "-on."));

		var index = $(this).index();
		$("#price-list li").hide();
		$("#price-list li").eq(index).show();
	});
});

タブ用とコンテンツ用のul,liを用意
相対するタブとコンテンツが同じ順に並ぶようにhtmlをかく

tab押したら、tabのli全部非アクティブの画像に切り替える
そのあと押したとこだけアクティブに

コンテンツも一度全部非表示にする
タブのliが何番目かしらべてそれに対するコンテンツを表示する

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?