slice() 메서드로 지정된 개체만 가져오기
.NET프로그래밍/jQuery 1.3.2 2009. 11. 6. 11:21 |[Slice.htm]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>slice() 메서드로 지정된 개체만 가져오기</title>
<style type="text/css">
.red { color:Red; }
</style>
<script src="js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// size() 해당 결과값(집합)의 개수
alert("현재 웹 페이지에는 " + $('input').size() + "개의 input 태그가 있다.");
// 2번째와 3번째만 스타일 적용
$('input').slice(1, 3).addClass('red'); // 1번째 인덱스에서 (3-1)번째 인덱스까지
});
</script>
</head>
<body>
<h1>2번째와 3번째 버튼에만 빨간 글씨 적용</h1>
<input type="button" value="버튼" />
<input type="button" value="버튼" />
<input type="button" value="버튼" />
<input type="button" value="버튼" />
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 위의 그림의 '메시지 박스'에 있는 '확인'버튼 클릭 후 화면.
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
toggleClass() 메서드로 CSS 클래스에 대한 토글링 (0) | 2009.11.06 |
---|---|
toggle() 메서드로 토글링 (0) | 2009.11.06 |
filter() 메서드를 사용해서 조건에 맞는 요소만 가져오기 (0) | 2009.11.06 |
특정 요소에 클릭 이벤트를 적용 (0) | 2009.11.06 |
This.id로 DOM 요소의 id 속성 가져오기 (0) | 2009.11.06 |