반응형
children( ) => 지정한 엘리먼트의 바로 아래 자식 노드 (parent( )는 부모 노드)
each( ) => 각각 엘리먼트에 차례로 접근
each( ) => 각각 엘리먼트에 차례로 접근
<html>
<head>
<title>jquery each()</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//root의 자식 노드 선택
var nodes=$("#root").children();
//nodes의 갯수를 alert
alert(nodes.length);
//변수 txt 선언
var txt="";
//nodes 의 각각 엘리먼트에 차례로 접근해서 txt에 입력
nodes.each(function(){
txt+=" "+$(this).text();
});
alert(txt);
});
</script>
</head>
<body>
<div id="root">
<div>Azit4u</div>
<div>S2ang</div>
<div>Hello</div>
</div>
</body>
</html>
반응형
'자바스크립트&jQuery' 카테고리의 다른 글
| jQuery bind(), unbind(), trigger() (0) | 2011.10.14 |
|---|---|
| google jQuery 최신 버전 지원(1.버전대) (0) | 2011.10.07 |
| 글자수 체크 하기 (0) | 2011.10.05 |
| javascript 메뉴 (0) | 2011.10.05 |
| jquery 기본 필터 (0) | 2011.07.31 |