简体   繁体   中英

Insert text in a table cell with d3

How can I add text to a cell using d3?

I have a function with the code that needs to be added and I'm calling this in the body of the html page. I have the following code as an example but it doesn't seem to be working.

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href ="styles.css">
<script type="text/javascript" src="http://d3js.org/d3.v4.min.js"></script>
<script type="text/javascript">
    function t1(){
    d3.select("td#target").text("14");
    }
</script>
</head>
<body onload="t1()">
  <table>
      <tr>
        <th>Name</th>
        <th>Surname</th> 
        <th>Age</th>
      </tr>
      <tr>
        <td>Tom</td>
        <td>Smith</td> 
        <td is="target"> </td>
      </tr>
  </table>
</body>
</html>

Any ideas on how to make this work.

It is a small mistake..

change <td is="target"> into <td id="target">

I found the solution. I figured out I had just a typo

<td is="target"> </td>

Should be

<td id="target"> </td>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM