jQuery - live()
script 2010/01/13 00:09HTML상의 있지도 않은 element에 대해 이벤트를 지정할 수 있다.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var index = 0;
$("p.test").live("click", function() {
alert($(this).text());
$(this).after("<p class=\"test\">클릭" + ++index + "</p>");
});
});
</script>
<style type="text/css">
p.test { background:#ccc; }
</style>
</head>
<body>
<p class="test">클릭</p>
</body>
</html>
live() 함수에 click 이벤트를 지정하여 앞으로 생길 p태그에 대해 이벤트를 지정할 수 있다.
Demo
클릭
'script' 카테고리의 다른 글
| [Link] javascript CDN(Content Delivery Network) Catalog (0) | 2010/07/08 |
|---|---|
| javascript document.referrer (0) | 2010/03/31 |
| javascript 세자리마다 콤마(,) 찍기 (0) | 2010/02/18 |
| javascript 상하 롤링 v1.0 (0) | 2010/01/31 |
| jQuery 1.4 Released (0) | 2010/01/16 |
| jQuery - live() (0) | 2010/01/13 |
| jQuery - data(), removeData() (0) | 2010/01/12 |
| window.onload 여러곳에서 사용하기 (0) | 2009/12/04 |
| [Link] jQuery Cheat Sheet (0) | 2009/11/05 |
| 마우스로 드래그해서 선택한 텍스트 가져오기 (0) | 2009/09/04 |
| 이미지 파일첨부시 업로드 이미지 미리보기 (IE8, Firefox 3) (19) | 2009/09/03 |
