I want to move a div element that is in a TD from one table to another TD of the same row, and I can not do it without errors, so I consult it to see if someone can help me:
<table>
<thead>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
</thead>
<tbody>
<tr>
<td> <div class="ABC"></div> <div class="Mover"><a href="/lolo/1"></a></div></td>
<td> </td>
<td> </td>
<td><a href="/lola/1"></a></td>
</tr>
<tr>
<td> <div class="ABC"></div> <div class="Mover"><a href="/lolo/2"></a></div></td>
<td> </td>
<td> </td>
<td><a href="/lola/2"></a></td>
</tr>
</tbody>
</table>
I'm trying with this code:
[].forEach.call(document.querySelectorAll('[href^="/lola/"]'), function(elem) {
var slw = elem.parentNode.parentNode.querySelector('.Mover');
//se encuentran los elementos con la clase "Mover" dentro de la misma FILA.
var slwdata = document.createElement('div');
slwdata.innerHTML = slw.outerHTML;
elem.parentNode.appendChild(slwdata);
});
Finally I try to add it to the current TD. First I received an error saying it was not a node so I am trying to do it by creating an element first.
Finally, the last TD of each ROW should be left like this:
<td>
<a href="/lola/2"></a>
<div class="Mover"><a href="/lolo/2"></a></div>
</td>
Eliminando el DIV con CLASE Mover de laa anteriores TD..
If the previous code is executed twice in the console it works (it does not erase the DIV OF the PREVIOUS td but that is not a problem because I can erase it, but the first time it gives the error: VM12047: 5 Uncaught TypeError: Can not read property 'outerHTML' of null at: 5: 29 at NodeList.forEach () at: 1: 12