Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery :last or :lastChild and how?

Tags:

jquery

class

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 :)

like image 871
SoLoGHoST Avatar asked Jan 30 '12 05:01

SoLoGHoST


1 Answers

Try this.

pTd.parent().children('.dp_add_section:last-child').remove();
like image 117
ShankarSangoli Avatar answered Sep 21 '22 15:09

ShankarSangoli