티스토리 뷰

WEB/jQuery

[jQuery] slice()

춘햄 2021. 6. 2. 14:56

요소 선택자가 배열 형태인 경우, slice() 메서드를 이용하여 끊어 해당 객체들을 조작할 수 있다.


<!DOCTYPE>

<html>
<head>
    <title>slice() 메서드로 지정된 개체만 가져오기</title>

    <style type="text/css">
        .red { color:Red; }
    </style>

    <script src="jquery-1.6.2.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
		$('input').slice(1, 3).addCladd('red');

        });
    </script>
</head>

<body>
	
	<h1>2번째와 3번째 버튼에만 빨간 글씨 적용</h1>
	
	<input type="button" value="버튼" /> <!-- 0번 -->
	<input type="button" value="버튼" /> <!-- 1번 -->
	<input type="button" value="버튼" /> <!-- 2번 -->
	<input type="button" value="버튼" /> <!-- 3번 -->

</body>

</html> 

 

'WEB > jQuery' 카테고리의 다른 글

[jQuery] hover()  (0) 2021.06.02
[jQuery] toggle()  (0) 2021.06.02
[jQuery] filter()  (0) 2021.06.02
[jQuery] addClass() & removeClass()  (0) 2021.06.02
[jQuery] jQuery의 기본, 선택자  (0) 2021.06.02
Comments