Trying to remove the last child of an element only if the class = "dp_add_section", otherwise, I don't want to remove the last child.
How do I do this in jQuery? Here's what I got so far, but it only removes the next element, can't wrap my head around trying to use the last selector for this...
if (pTd.next().attr('class') == 'dp_add_section')
pTd.next().remove(".dp_add_section");
pTd is a variable that obtains the actual element that I need for this. So if I use pTd.parent()
this gives me the <tr>
element, but how do I remove the last <td>
within here ONLY if the last <td>
element has a class="dp_add_section"
?
Thanks guys :)
Try this.
pTd.parent().children('.dp_add_section:last-child').remove();
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