IT/jQuery
jQuery - append(), appendTo(), prepend()
노마드오브
2018. 10. 13. 21:12
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
// innerHTML 또는 html()처럼 HTML태그가 살아서 삽입됨
// append() 뒤에 추가
// appendTo() 뒤에 추가
// prepend() 앞에 추가
var h1 = '<h1>header1</h1>';
var h2 = '<h2>header2</h2>';
$('body').append(h2);
$('body').prepend(h1);
$(h1).appendTo('body');
});
</script>
</head>
<body>
본문
</body>
</html>