Manipulation - DOM 요소의 앞/뒤에 요소 추가
.NET프로그래밍/jQuery 1.3.2 2009. 11. 11. 09:49 |
[InsertAfter.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>DOM 요소의 앞/뒤에 요소 추가</title>
<style type="text/css">
.Chapter { background-color:Silver; }
.Content { height:100px; border:1px solid red; }
</style>
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//[1] 내용 뒤에 구분선(<hr />) 삽입
$('<hr />').insertAfter(".Content");
//[2] TOP 링크를 Chapter 앞에 추가
$('p.Chapter:gt(0)').before("<a href='#'>TOP</a>");
});
</script>
</head>
<body>
<p class="Chapter">1 장</p>
<div class="Content">
내용...
</div>
<p class="Chapter">2 장</p>
<div class="Content">
내용...
</div>
<p class="Chapter">3 장</p>
<div class="Content">
내용...
</div>
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 아래그림에서 '링크'가 걸린 "TOP"텍스트를 마우스로 클릭하면 '웹 페이지'의 맨 위로 이동한다.
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
Manipulation - Wrap()메서드 (검색된 요소를 특정 태그로 감싸기) (0) | 2009.11.11 |
---|---|
Manipulation - 특정 용어에 대해서 번호 붙이기 (0) | 2009.11.11 |
Manipulation - Append() 메서드 (DOM 요소 생성 후 원하는 요소에 추가) (0) | 2009.11.11 |
Traversing - 방금 실행한 집합 이전으로 되돌리기 (0) | 2009.11.10 |
Traversing - 지정된 표현식을 제외한 집합 가져오기 (0) | 2009.11.10 |