Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you need to actually replace the td you are selecting from the DOM, then you need to first go to the parentNode, then <strike>replace the contents</strike> replace the innerHTML with a new html string representing what you want. The trick is converting the first-table-cell to a string so you can then use it in a string replace method.</p> <p>I added a fiddle example: <a href="http://jsfiddle.net/vzUF4/" rel="nofollow">http://jsfiddle.net/vzUF4/</a></p> <pre><code>&lt;table&gt;&lt;tr&gt;&lt;td id="first-table-cell"&gt;0&lt;/td&gt;&lt;td&gt;END&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;script&gt; var firstTableCell = document.getElementById('first-table-cell'); var tableRow = firstTableCell.parentNode; // Create a separate node used to convert node into string. var renderingNode = document.createElement('tr'); renderingNode.appendChild(firstTableCell.cloneNode(true)); // Do a simple string replace on the html var stringVersionOfFirstTableCell = renderingNode.innerHTML; tableRow.innerHTML = tableRow.innerHTML.replace(stringVersionOfFirstTableCell, '&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;'); &lt;/script&gt; </code></pre> <p>A lot of the complexity here is that you are mixing DOM methods with string methods. If DOM methods work for your application, it would be much bette to use those. <strike> You can also do this with pure DOM methods (document.createElement, removeChild, appendChild), but it takes more lines of code and your question explicitly said you wanted to use a string.</strike></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload