sundries
2-3 filter(function(index))
스티브
2018. 1. 12. 19:39
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src ="../js/jquery-3.2.1.js"></script>
</head>
<!-- 기본 필터 메서드
filter() : 문서 객체를 필터링합니다.
형식) $(selector).filter(selector);
$(selector).filter(function(){});
-->
<script>
$(function(){
$('h3').filter(function(index){
return index % 3 == 0;// index가 3의 배수일 경우
})
.css({ backgroundColor:'orange',
color:'yellow'
});
});
</script>
<body>
<h3>Header-0</h3>
<h3>Header-1</h3>
<h3>Header-2</h3>
<h3>Header-3</h3>
<h3>Header-4</h3>
<h3>Header-5</h3>
<h3>Header-6</h3>
</body>
</html>
![]()