jQuery

jQuery In Action chapter2-1

우혁이 아빠 2009. 12. 19. 13:11
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>새로운 &lt;div&gt; 예제</title>
 <script type="text/javascript" src="../js/jquery-1.2.1.js" ></script>
 <script type="text/javascript">
 $(function () {
  $("<div class='foo'>내가 foo를 가졌다!</div><div>나는 foo를 가지지 않았다.</div>")
   .filter(".foo").click(function () {
    alert("내가 foo이다!");
  }).end().appendTo("#someParentDiv");
 });
 // <div>엘리먼트를 두 개 생성한다.
 // end() 메서드를 이용해 필터링 이전의 두 <div> 엘리먼트를 지닌
 // 집합으로 돌아간뒤, appendTo 실행
 </script>
</head>
<body>
 <div>Div 1</div>
 <div id="someParentDiv">Div 2</div>
 <div>Div 3</div>
</body>
</html>