คำอธิบาย
ใช้ document.querySelectorAll().forEach() เพื่อวนลูปตรวจสอบและเปลี่ยนค่าในแต่ละเซลล์
ตัวอย่างโค้ด
<table>
<tr><td class="demo"> Java </td></tr>
<tr><td class="demo"> MySQL </td></tr>
</table>
<script>
document.querySelectorAll(".demo").forEach(function (obj) {
if (obj.innerText.trim() === "MySQL") obj.innerText = "Javascript";
if (obj.innerText.trim() === "MongoDB") obj.innerText = "Python";
});
</script>
ผลลัพธ์
เซลล์ที่มี "MySQL" จะเปลี่ยนเป็น "Javascript"