반응형
children( ) => 지정한 엘리먼트의 바로 아래 자식 노드 (parent( )는 부모 노드)
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>

 

http://azit4u.phps.kr/jquery/each.html

반응형

+ Recent posts