JS. How to replace html element with another element/text, represented in string?
- by EL 2002
I have a problem with replacing html elements.
For example, there is a table
<table><tr><td id="idTABLE">0</td><td>END</td></tr></table>
(it can be div, span, anything)
And string in JS script
var str='<td>1</td><td>2</td>';
(it can be anything, '123 text', '<span123 element</span 456' or ' <tr<td123</td ' or anything)
How can I replace element 'idTABLE' with str? I mean really replace, so
<table><tr><td id="__TABLE__">0</td><td>END</td></tr></table>
becomes
<table><tr><td>1</td><td>2</td><td>END</td></tr></table>
//str='<td>1</td><td>2</td>';
<table><tr>123 text<td>END</td></tr></table>
//'123 text'
<table><tr> tr><td>123</td> <td>END</td></tr></table>
//' <tr><td>123</td> '
I tried with createElement, replaceChild, cloneNode, but with no result at all =(