:lt(n) 예제
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("li:lt(2)").css("background-color", "yellow"); $("li:gt(2)").css("background-color", "tomato"); }); </script> <ul> <li>0</li> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> 결과보기
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("li:lt(2)").css("background-color", "yellow");
$("li:gt(2)").css("background-color", "tomato");
});
</script>
<ul>
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
결과보기
:lt(n) 정의
n번째 미만 요소. (※ 색인번호는 0부터 시작. n번째는 포함 X) 1. 보통 다른 선택자와 함께 사용. 2. :gt(n) 선택자 : 색인번호 n 번째 초과 요소.
n번째 미만 요소. (※ 색인번호는 0부터 시작. n번째는 포함 X)
1.
보통 다른 선택자와 함께 사용.
2.
:gt(n) 선택자 : 색인번호 n 번째 초과 요소.
:lt(n) 구문
$(":lt(n)") [매개변수] n 색인번호. (※ 색인번호는 0부터 시작)
$(":lt(n)")
[매개변수]
n
색인번호. (※ 색인번호는 0부터 시작)