JQuery/JQuery 기본
[JQuery] length 길이 확인하기.
연찌현찌
2018. 8. 7. 11:01
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<ul class="list">
<li>coffee</li>
<li>tea</li>
<li>milk</li>
<li>green tea</li>
</ul>
<script type="text/javascript">
$(function () {
//list의 길이(교수 방법????) // .list (방법: 호 실무자)
var len = $("ul.list").children().length;
alert("list의 길이는" + len +"개입니다.");
//마우스를 list 클릭시 배열의 길이값 체크 됨.
$("ul.list").children().click(function () {
var cho = $("ul.list").children().index(this);
alert("선택한 요소는 " + cho + "입니다.");
});
});
</script>
</body>
</html>