0

I have dynamic table with unique row id e.g , , , also having checkbox for every row.

using jquery i fetch all the selected ids (comma separated, e.g 1,25,4) of that checkboxes. All i need to remove those selected tr's after jquery success. see my below code:

getting comma separated ids:

var ids = $(".chk:checked").map(function() {
                    return this.id;
                }).get().join(",");

condition:

if(response == 0){
                            alert('Sorry! There is some problem in server, try again.');
                            return false;
                        }else {
                            alert("Successfully removed from library.");
                            $('#tr_'+ids).remove();
                        }

enter image description here

3
  • 2
    Can you create a working snippet (using the [<>] button when you edit your post) with some HTML content ? Commented Dec 19, 2018 at 13:29
  • i have edit my question and also attached image, please have a look Commented Dec 19, 2018 at 13:32
  • 1
    An image is not helpful to actually launch the script, see what happens, and debug the problem… Can't you add some of your HTML to create a snippet ? Commented Dec 19, 2018 at 13:34

2 Answers 2

1

If you add all ids to an array you can then use this to remove the rows

$.each(ids, function(key, val){
    $('#tr_' + val).remove();
});
Sign up to request clarification or add additional context in comments.

Comments

0

$('#tr_'+ids) would end up looking like $('#tr_1,3,7,9') which is an invalid selector

You could do things like:

$("tr").has('.chk:checked').remove()

// OR 

$(".chk:checked").closest('tr').remove()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.