Manipulation - ReplaceWith() 메서드 (검색된 요소를 변경하기)
.NET프로그래밍/jQuery 1.3.2 2009. 11. 11. 10:50 |
[ReplaceWith.htm]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>검색된 요소를 변경하기</title>
<style type="text/css">
button { display:block; margin:3px; color:red; width:200px; }
div { color:red; border:2px solid blue; width:200px;
margin:3px; text-align:center; }
</style>
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
// 모든 버튼 요소 클릭시
$("button").click(function() {
// 나자신(버튼)을 <div> 태그로 변경하자.
$(this).replaceWith("<div>" + $(this).text() + "</div>");
});
});
</script>
</head>
<body>
<button>First</button>
<button>Second</button>
<button>Third</button>
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 첫 화면.
--> 첫 번째 버튼을 클릭하면 아래그림과 같이 해당 버튼이 "<div> 태그"로 변경된다.
--> 두 번째 버튼을 클릭하였을 때의 화면.(해당버튼이 "<div> 태그"로 변경되었다.)
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
CSS - Width() / Height() 메서드 (검색된 요소의 크기 구하기) (0) | 2009.11.11 |
---|---|
Manipulation - Remove() 메서드 (검색된 요소를 완전 제거) (0) | 2009.11.11 |
Manipulation - Clone() 메서드 (검색된 요소를 복사하기) (0) | 2009.11.11 |
Manipulation - Wrap()메서드 (검색된 요소를 특정 태그로 감싸기) (0) | 2009.11.11 |
Manipulation - 특정 용어에 대해서 번호 붙이기 (0) | 2009.11.11 |