Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Remove rows based on class

I've got a problem with jQuery and removing some elements based on their class. See http://jsfiddle.net/JBKp4/1/

When the delete link is clicked in the itemRow the optionRow's and commentRow of that Item should be delete asswell. But I'cant determine the class of the row.

I hope somebody can help me out. Thank you!

like image 728
tom Avatar asked Oct 18 '12 16:10

tom


1 Answers

your code can be much simpler:

$('body').on('click', '.delete', function() {
    var $tr = $(this).closest('tr');
    if ($tr.attr('class') == 'itemRow') {
        $tr.nextUntil('tr[class=itemRow]').andSelf().remove();
    }
    else {
        $tr.remove();
    }
});

see it working here: http://jsfiddle.net/RASG/MeaRQ/

like image 104
RASG Avatar answered Sep 24 '22 08:09

RASG