HTML DOM ColumnGroup 개체는 HTML
속성
다음은 ColumnGroup 속성입니다 -
| 속성 | 설명 |
|---|---|
| 스팬 | 열 그룹의 범위 속성 값을 설정하거나 반환합니다. |
구문
다음은 −
의 구문입니다.ColumnGroup 개체 만들기 -
var x = document.createElement("COLGROUP"); 예시
ColumnGroup 개체에 대한 예를 살펴보겠습니다. -
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
#DIV1{
background-color:pink;
}
</style>
</head>
<body>
<table id="TABLE1">
<tr>
<th>FRUIT</th>
<th>COLOR</th>
<th>Price</th>
</tr>
<tr>
<td>MANGO</td>
<td>YELLOW</td>
<td>100RS</td>
</tr>
<tr>
<td>GUAVA</td>
<td>GREEN</td>
<td>50RS</td>
</tr>
</table>
<p>Click the below button to create a colgroup element with span = 2.</p>
<button onclick="colFun()">COLGROUP</button>
<script>
function colFun() {
var x = document.createElement("COLGROUP");
x.setAttribute("id","DIV1");
x.setAttribute("span","2");
document.getElementById("TABLE1").appendChild(x);
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

COLGROUP −
클릭 시

위의 예에서 -
먼저 3개의 행과 3개의 열과 id "TABLE 1"이 있는 테이블을 만들었습니다. 우리는 또한 테이블과 그 자식 요소에 몇 가지 스타일을 적용했습니다 -
table, th, td {
border: 1px solid black;
}
<table id="TABLE1">
<tr>
<th>>FRUIT</th>
<th>COLOR</th>
<th>Price</th>
</tr>
<tr>
<td>MANGO</td>
<td>YELLOW</td>
<td>100RS</td>
</tr>
<tr>
<td>GUAVA</td>
<td>GREEN</td>
<td>50RS</td>
</tr>
</table> 그런 다음 사용자가 클릭하면 colFun()을 실행할 버튼 COLGROUP을 만들었습니다.
<button onclick="colFun()">COLGROUP</button>
colFun() 메서드는