I have this code:
<td>
<div id="vB_Editor_QR_cmd_email" class="imagebutton">
abc
</div>
</td>
I want put another element to this code like this:
<p>blablablalblablab</p>
<td>
<div id="vB_Editor_QR_cmd_email" class="imagebutton">
abc
</div>
</td>
I use this code
$("#vB_Editor_QR_cmd_insertimage").before("<p>blablablalblablab</p>");
but it only put before div tag.
<td>
<p>blablablalblablab</p>
<div id="vB_Editor_QR_cmd_email" class="imagebutton">
abc
</div>
</td>
I want it like this
<p>blablablalblablab</p>
<td>
<div id="vB_Editor_QR_cmd_email" class="imagebutton">
abc
</div>
</td>
Insert an Element Before AnotherThe insertBefore() function selects the parent element of the existing node and calls the insertBefore() method to insert the new node before the existing node.
prepend() The Element. prepend() method inserts a set of Node objects or string objects before the first child of the Element . String objects are inserted as equivalent Text nodes.
There's no prependChild , but prepending can be done using the insertBefore() .
Try this,
$("#vB_Editor_QR_cmd_insertimage").parents("td:first").before("<p>blablablalblablab</p>");
parents("td:first") will return first parent of div
hope this help.....
Use before or insertBefore to place an element before another.
$("<p>blablablalblablab</p>").insertBefore("td");
or
$("td").insertBefore("<p>blablablalblablab</p>");
or more specifical to your html:
$("vB_Editor_QR_cmd_email").parent("td").before(...);
Though unless this is just a (bad) example, this is invalid. You can't have a <p>
tag directly before a <td>
because that would imply that the <p>
is within a <tr>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With