$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>JavaScript, getting value of a td with id name - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

JavaScript, getting value of a td with id name - Stack Overflow

matteradmin23PV0评论

Originally I was using input with an id and grabbing it's value with getElementById. Currently, I'm playing with <td>s. How can I grab the values of the <td>?

Originally I used:

<input id="hello">
document.getElementById("hello").value;

Now I want to get value of <td>, but I don't know how;

<td id="test">Chicken</td>
<td>Cow</td>

Edit: What's the difference between textContent, innerHTML, and innerText?

Originally I was using input with an id and grabbing it's value with getElementById. Currently, I'm playing with <td>s. How can I grab the values of the <td>?

Originally I used:

<input id="hello">
document.getElementById("hello").value;

Now I want to get value of <td>, but I don't know how;

<td id="test">Chicken</td>
<td>Cow</td>

Edit: What's the difference between textContent, innerHTML, and innerText?

Share Improve this question edited Sep 28, 2012 at 12:11 S.L. Barth is on codidact.com 8,24571 gold badges53 silver badges67 bronze badges asked Feb 22, 2010 at 10:13 StrawberryStrawberry 67.8k58 gold badges155 silver badges204 bronze badges
Add a comment  | 

8 Answers 8

Reset to default 123

To get the text content

document.getElementById ( "tdid" ).innerText

or

document.getElementById ( "tdid" ).textContent

var tdElem = document.getElementById ( "tdid" );
var tdText = tdElem.innerText | tdElem.textContent;

If you can use jQuery then you can use

$("#tdid").text();

To get the HTML content

var tdElem = document.getElementById ( "tdid" );
var tdText = tdElem.innerHTML;

in jQuery

$("#tdid").html();

use the

innerHTML 

property and access the td using getElementById() as always.

Again with getElementById, but instead .value, use .innerText

<td id="test">Chicken</td>
document.getElementById('test').innerText; //the value of this will be 'Chicken'

If by 'td value' you mean text inside of td, then:

document.getElementById('td-id').innerHTML

For input you must have used value to grab its text but for td, you should use innerHTML to get its html/value. Example:

alert(document.getElementById("td_id_here").innerHTML);

To get its text though, use:

alert(document.getElementById("td_id_here").innerText);

.innerText doesnt work in Firefox.

.innerHTML works in both the browsers.

Have you tried: getElementbyId('ID_OF_ID').innerHTML?

if i click table name its shown all fields about table. i did table field to show. but i need to know click function.

My Code:

$sql = "SHOW tables from database_name where tables_in_databasename not like '%tablename' and tables_in_databasename not like '%tablename%'";


$result=mysqli_query($cons,$sql);

$count = 0;

$array = array();

while ($row = mysqli_fetch_assoc($result)) {

    $count++;

    $tbody_txt .= '<tr>';

    foreach ($row as $key => $value) {
        if($count  == '1') {
            $thead_txt .='<td>'.$key.'</td>';
        }
        $tbody_txt .='<td>'.$value.'</td>';


        $array[$key][] = $value;
    }
}?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far