0
How to insert an item via Jquery so that it is BEFORE and OUT of a specific item (accepted edits to improve the way you ask).
The following example inserts before, but inside the item add-mesa-de-luz-button
.
$("#add-mesa-de-luz-button").click(function () {
$("#add-mesa-de-luz-button").prepend(
"<tr><td>Item adicionado</td></tr>"
);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>Item 1</td>
</tr>
<tr>
<td>Item 2</td>
</tr>
<tr id="add-mesa-de-luz-button">
<td>Botão de adicionar</td>
</tr>
</table>
The HTML output looks like this:
<table>
<tr>
<td>Item 1</td>
</tr>
<tr>
<td>Item 2</td>
</tr>
<tr id="add-mesa-de-luz-button">
<tr><td>Item adicionado</td></tr>
<td>Botão de adicionar</td>
</tr>
</table>
But I would like it to be inserted before and outside the item add-mesa-de-luz-button
, so that it stays that way:
<table>
<tr>
<td>Item 1</td>
</tr>
<tr>
<td>Item 2</td>
</tr>
<tr><td>Item adicionado</td></tr>
<tr id="add-mesa-de-luz-button">
<td>Botão de adicionar</td>
</tr>
</table>
Utilize
before
instead ofprepand
– Valdeir Psr