TableRow कोशिकाओं का संग्रह
उदाहरण
पहली पंक्ति में कक्षों की संख्या दिखाएँ:
var x = document.getElementById("myTable").rows[0].cells.length;
एक्स का परिणाम होगा:
2
नीचे और अधिक "इसे स्वयं आज़माएं" उदाहरण।
परिभाषा और उपयोग
कक्ष संग्रह तालिका पंक्ति में सभी <td> या <th> तत्वों का संग्रह देता है।
नोट: संग्रह में तत्वों को सॉर्ट किया जाता है जैसे वे स्रोत कोड में दिखाई देते हैं।
ब्राउज़र समर्थन
Collection | |||||
---|---|---|---|---|---|
cells | Yes | Yes | Yes | Yes | Yes |
वाक्य - विन्यास
tableObject.cells
गुण
Property | Description |
---|---|
length | Returns the number of <td> and/or <th> elements in the collection. Note: This property is read-only |
तरीकों
Method | Description |
---|---|
[index] | Returns the <td> and/or <th> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <td> and/or <th> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <td> and/or <th> element from the collection with the specified id. Note: Returns null if the id does not exist |
टेक्निकल डिटेल
डोम संस्करण: | कोर स्तर 2 दस्तावेज़ वस्तु |
---|---|
प्रतिलाभ की मात्रा: | एक HTMLCollection ऑब्जेक्ट, जो <tr> तत्व में सभी <td> और/या <th> तत्वों का प्रतिनिधित्व करता है। संग्रह में तत्वों को क्रमबद्ध किया जाता है क्योंकि वे स्रोत कोड में दिखाई देते हैं |
और ज्यादा उदाहरण
उदाहरण
[ सूचकांक ]
तालिका की पहली पंक्ति में पहले सेल के आंतरिक HTML को अलर्ट करें:
alert(document.getElementById("myTable").rows[0].cells[0].innerHTML);
उदाहरण
आइटम ( सूचकांक )
तालिका की पहली पंक्ति में पहले सेल के आंतरिक HTML को अलर्ट करें:
alert(document.getElementById("myTable").rows[0].cells.item(0).innerHTML);
उदाहरण
नामित आइटम ( आईडी )
तालिका की पहली पंक्ति में id="myTd" के साथ सेल के आंतरिक HTML को अलर्ट करें:
alert(document.getElementById("myTable").rows[0].cells.namedItem("myTd").innerHTML);
उदाहरण
पहली टेबल सेल की सामग्री बदलें:
var x = document.getElementById("myTable").rows[0].cells;
x[0].innerHTML = "NEW CONTENT";
टेबलरो ऑब्जेक्ट