■ 프론트엔드 ■/jQuery

append() - 마지막 자식 요소 추가

serpiko 2013. 10. 13. 22:53

.append( content, [content] )Returns : jQuery

개요 : 어떤 요소에 마지막 자식 요소를 새로 추가합니다.

Description: Insert content, specified by the parameter, to the end of each element in the set of matched elements.

  • .append( content, [content] )
  • content 추가될 HTML 문자열, DOM 요소, 또는 jQuery 객체.
  • content 추가될 하나 이상 복수개의 DOM 요소들, 요소 배열, HTML 문자열들, 또는 jQuery 객체들.
  • .append( function(index, html) )
  • function(index, html) 선택된 요소 집합의 각 요소 별로 추가될 HTML 문자열을 반환해주는 함수. 집합을 구성하는 요소들의 인덱스를 인자로 받을 수 있습니다.

인자로 올 수 있는 것들은 DOM 요소들, jQuery 객체들, HTML 문자열들, 그리고 DOM 요소들의 배열들이 있습니다.

 

예제)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html>
<head>
  <style>
  p { background:yellow; }
</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <p>I would like to say: </p>
<script>
  $("p").append("<strong>Hello</strong>");
</script>
 
</body>
</html>

 

결과)