<html lang="ko">
<head>
<meta charset="UTF-8">
<title>jQuery Element Insert</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
table, tr, td {
border: 2px solid red;
border-collapse: collapse;
}
table { margin-bottom: 15px; }
</style>
<script>
$(function() {
$("button").on("click", function() {
// id가 "secondColumn"인 요소의 바로 앞에 새로운 <td>요소를 추가함.
$("<td>새로운 셀이에요!</td>").insertBefore("#secondColumn");
});
});
</script>
</head>
<body>
<h1>.insertBefore() 메소드</h1>
<table>
<tr>
<td>첫 번째 셀이에요!</td>
<td id="secondColumn">두 번째 셀이에요!</td>
</tr>
</table>
<button>셀 추가</button>
</body>
</html>