[Javascript] Tr Td 접근하기

2014. 7. 7. 17:15프로그래밍/Javascript & JQuery

1. Javascript Table Tr Td 접근하기

TR은 rows 

TD는 cells 

접근 가능하며 , 배열형식으로 접근 할 수 있다.


example.html

=========================================================================================

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

<script>

function test(){

var table1 = document.getElementById("table1");

table1.rows[0].cells[0].innerHTML = "hello";

table1.rows[0].cells[1].innerHTML = "world";

table1.rows[1].cells[0].innerHTML = "hey";

table1.rows[1].cells[1].innerHTML = "man";

}

</script>

</head>

<body>

<table id="table1">

<tr>

<td>1</td>

<td>2</td>

</tr>

<tr>

<td>3</td>

<td>4</td>

</tr>

</table>

<input type="button" value="test1" onClick="test();"/>

</body>

</html>

=========================================================================================