본문 바로가기

작업/작업소스

[jquery제이쿼리] 네비 소스 by허팀장님





<!DOCTYPE html>

<html>

<head>

<script src="//code.jquery.com/jquery-1.4.2.min.js"></script>

</head>

<body>

<div>

<button class='one'>ONE</button>

<button class='two'>TWO</button>

<button class='three'>THREE</button>

</div>

<div class='sub_one'>

<button class='sub_one_1'>SUB_ONE_1</button>

<button class='sub_one_2'>SUB_ONE_2</button>

<button class='sub_one_3'>SUB_ONE_3</button>

<button class='sub_one_4'>SUB_ONE_4</button>

</div>

<div class='sub_two'>

<button class='sub_two_1'>SUB_TWO_1</button>

<button class='sub_two_2'>SUB_TWO_2</button>

<button class='sub_two_3'>SUB_TWO_3</button>

</div>

<div class='sub_three'>

<button class='sub_three_1'>SUB_THREE_1</button>

<button class='sub_three_2'>SUB_THREE_2</button>

<button class='sub_three_3'>SUB_THREE_3</button>

</div>

<script>

$("body > div > button").click(function() { // or "body > div > :button"

/*

$("body > div[class^='sub_']").hide();

$("body > div[class$='" + $(this).attr('class') + "']").show();

*/


var idx = $("body > div:first > :button").index($(this));

$("body > div:not(:first)").hide();

// $("body > div:not(:first)").eq(idx).show();

$("body > div:not(:first):eq(" + idx + ")").show();

});

</script>

</body>

</html>