Insert HTML element inside the first child of another element. JQuery

0

I want in the following code, to move the element .buscarusuarios within the first TD son of the TR classe fltrow, once the sun starts. I'm a little lost with the CSS3 selectors

<form class="buscarusuarios">
<input class="form-control mr-sm-2" id="myInput" onkeyup="myFunction()"  
type="search" placeholder="Search" aria-label="Search">     
</form>

<tr class="fltrow">
<td>Prueba</td>
<td>Prueba</td>
<td>Prueba</td>
<td>Prueba</td>
<td>Prueba</td>       
</tr>
    
asked by Sergio Cristiá 10.11.2018 в 11:38
source

1 answer

0

For this you need to clone the form with .cloneNode , add the clone to the element you want with appendChild () and finally delete the initial form using parentNode.removeChild . It's not jQuery, it's javascript. I hope it's useful.

let primer_hijo_de_fltrow = document.querySelector("table .fltrow td")

let formulario = document.querySelector(".buscarusuarios");

let nuevo_formulario = formulario.cloneNode(true);
primer_hijo_de_fltrow.appendChild(nuevo_formulario);

formulario.parentNode.removeChild(formulario);
td{border:1px solid;}
<form class="buscarusuarios">
<input class="form-control mr-sm-2" id="myInput" onkeyup="myFunction()"  
type="search" placeholder="Search" aria-label="Search">     
</form>


<table>
<tr class="fltrow">
<td>Prueba</td>
<td>Prueba</td>
<td>Prueba</td>
<td>Prueba</td>
<td>Prueba</td>       
</tr>
</table>
    
answered by 10.11.2018 / 12:12
source