본문 바로가기
Programming/JavaScript

Table insertRow() Method

by 막이 2013. 11. 27.

Definition and Usage

The insertRow() method inserts a new row at the specified index in a table.

Syntax

tableObject.insertRow(index)


ValueDescription
index

An integer that specifies the position of the row to insert (starts at 0).  

The value of -1 can also be used; which result in that the new row will be inserted at the last position.

This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari.

If this parameter is omitted, insertRow() inserts a new row at the last position in IE and at the first position in Chrome and Safari



Browser Support

    

The insertRow() method is supported in all major browsers.

 

Example

Example

Insert new rows at the first position of the table:

<html>
<head>
<script>
function displayResult()
{
var table=document.getElementById("myTable");
var row=table.insertRow(0);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
cell1.innerHTML="New";
cell2.innerHTML="New";
}
</script>
</head>
<body>

<table id="myTable" border="1">
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<br>
<button type="button" onclick="displayResult()">Insert new row</button>

</body>
</html>

[출처] Table insertRow() Method|작성자 zumerfolg


'Programming > JavaScript' 카테고리의 다른 글

[jquery]jquery widget example  (0) 2014.03.07
문자 byte 수 체크하기  (0) 2013.12.05
ajax 사용법  (0) 2013.11.08
동적 폼 추가 삭제  (0) 2013.10.30
[jquery] jquery 로 체크박스 리스트의 체크된 값들 가져오기  (0) 2013.09.13