메뉴 활성화 도움 좀 주세요ㅠㅠ
본문
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>무제 문서</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<style type="text/css">
ul {list-style-type:none;max-width:200px;}
.list {border:1px solid #cccccc;padding:5px;} /* 기본 css 및 선택하지 않은 경우 */
.list.on {border:1px solid #000000;} /* 선택한 경우 css */
</style>
<ul>
<li class="list"><a href="javascript:;">1. okkks.tistory.com</a></li>
<li class="list on"><a href="javascript:;">2. okkks.tistory.com</a></li>
<li class="list"><a href="javascript:;">3. okkks.tistory.com</a></li>
<li class="list"><a href="javascript:;">4. okkks.tistory.com</a></li>
<li class="list"><a href="javascript:;">5. okkks.tistory.com</a></li>
</ul>
<script type="text/javascript">
$('li').click(function() {
$('li').removeClass('on');
$(this).addClass('on');
});
</script>
</body>
</html>
답변 1
$('li').click(function() {
$('li').attr('class', 'list');
//1번 방법
$(this).addClass('on');
//2번방법
$(this).attr('class', 'list on');
});