HTML DOM ColumnGroup span गुण HTML
सिंटैक्स
−
. के लिए वाक्य रचना निम्नलिखित हैकॉलमग्रुप स्पैन प्रॉपर्टी सेट करना -
columngroupObject.span = number
यहां, संख्या उन स्तंभों की संख्या निर्दिष्ट करती है जिन पर
उदाहरण
आइए कॉलमग्रुप स्पैन प्रॉपर्टी के लिए एक उदाहरण देखें -
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid blue;
}
</style>
</head>
<body>
<table>
<colgroup id="Colgroup1"></colgroup>
<tr>
<th>Fruit</th>
<th>COLOR</th>
<th>Price</th>
</tr>
<tr>
<td>watermelon</td>
<td>dark green</td>
<td>40Rs</td>
</tr>
<tr>
<td>papaya</td>
<td>yellow</td>
<td>30Rs</td>
</tr>
</table>
<p>lick the button to change the background color of the first two columns.
<button onclick="changeColor()">CHANGE</button>
<script>
function changeColor() {
document.getElementById("Colgroup1").span = "2";
document.getElementById("Colgroup1").style.backgroundColor = "lightgreen";
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -

चेंज बटन पर क्लिक करने पर -

उपरोक्त उदाहरण में -
हमने दो पंक्तियों और तीन स्तंभों के साथ एक तालिका बनाई है। तालिका, वें और टीडी तत्वों पर कुछ स्टाइल भी लागू है -
table, th, td {
border: 1px solid blue;
}
<table>
<colgroup id="Colgroup1"></colgroup>
<tr>
<th>Fruit</th>
<th>COLOR</th>
<th>Price</th>
</tr>
<tr>
<td>watermelon</td>
<td>dark green</td>
<td>40Rs</td>
</tr>
<tr>
<td>papaya</td>
<td>yellow</td>
<td>30Rs</td>
</tr>
</table> इसके बाद हमने एक बटन चेंज बनाया है जो उपयोगकर्ता द्वारा क्लिक किए जाने पर चेंजकलर () विधि को निष्पादित करेगा।
<button onclick="changeColor()">CHANGE</button>
changeColor() फ़ंक्शन getElementById() विधि का उपयोग करके
function changeColor() {
document.getElementById("Colgroup1").span = "2";
document.getElementById("Colgroup1").style.backgroundColor = "lightgreen";
}