JavaScript Table Cell Value Retrieval

Margaret Jul 30, 2026

Ever found yourself нужко to extract data from HTML tables using JavaScript? You're not alone. tables are a staple in web development, and often, you'll need to access their data programmatically. One way to do this is by obtaining the value of a specific table cell. In this guide, we'll show you several methods on **how to get table cell value using JavaScript**.

📊 Combine Table Cells in HTML
📊 Combine Table Cells in HTML

Before we dive in, let's assume we have the following simple HTML table:

Sortable HTML Table With Javascript
Sortable HTML Table With Javascript
Header 1 Header 2
Data 1 Data 2

Using Plain JavaScript

Dynamically hide column values of html table using jquery
Dynamically hide column values of html table using jquery

One of the simplest ways to get a table cell value is by directly accessing the `innerHTML` property. This method provides easy access to the text content of the cell.

Let's say we want to get the value of the first data cell. Here's how you do it:

🧾 How to Create Tables in HTML
🧾 How to Create Tables in HTML

var cellValue = document.querySelector('td').innerHTML;

Accessing Cells Using Indexes

If your table is straightforward, you can access cells by their indexes. Here's how you get the value of the second cell in the first row:

HOW TO MERGE TABLE CELLS IN HTML
HOW TO MERGE TABLE CELLS IN HTML

var cellValue = document.getElementsByTagName('tr')[0].cells[1].innerHTML;

Accessing Cells Using IDs

For larger or more complex tables, it's useful to give each cell an ID. This allows you to access the cell directly, like this:

JavaScript Return Values: Get the Most Out of Your Functions 🚀
JavaScript Return Values: Get the Most Out of Your Functions 🚀

var cellValue = document.getElementById('cell1').innerHTML;

Using JavaScript Frameworks

JavaScript calculator projet
JavaScript calculator projet
Sortable Table with HTML & Javascript
Sortable Table with HTML & Javascript
Simple Searchable Table In HTML Javascript
Simple Searchable Table In HTML Javascript
How to Display HTML Table selected Row Data Into Input Field Using Jquery
How to Display HTML Table selected Row Data Into Input Field Using Jquery
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Full Notes Every Beginner Must Save 💡
How to Use Excel VBA to Filter a Pivot Table Based on Cell Value (3 Methods) - ExcelDemy
How to Use Excel VBA to Filter a Pivot Table Based on Cell Value (3 Methods) - ExcelDemy
The table-layout property in CSS
The table-layout property in CSS
JavaScript array methods
JavaScript array methods
JavaScript Cheat Sheet
JavaScript Cheat Sheet

Many JavaScript frameworks and libraries provide methods to simplify table cell access. We'll briefly look at two popular ones.

jQuery

jQuery provides the `text()` and `html()` methods to retrieve cell content. Here's how you get the value of the first data cell using jQuery:

var cellValue = $('td').text();

Puppeteer

Puppeteer is a Node library that provides a high-level API to control headless Chrome or Chromium. To retrieve a cell's content, you can use the `evaluate()` method within an async function, like this:

// Assuming the page is loaded within Puppeteer's context let cellValue = await page.evaluate(el => el.innerHTML, await document.querySelector('td'));

In modern web applications, data manipulation often involves manipulating DOM elements dynamically. Understanding how to retrieve table cell values is a crucial skill in manipulating table data with JavaScript. With the methods outlined above, you should now be well-equipped to handle various table data retrieval tasks in your projects.

Happy coding, and may your JavaScript tables always be as easy to work with as they are to look at!