Why does jquert get the parent element of the parent always reporting an error?

clipboard.png

clipboard.png
jquert checkboxcheckbox

clipboard.png

Mar.10,2021

use [I] to get the dom object, and the dom object has no parent method, so you need to use eq (i) to get the jquery object:

.
$(".checkboxdele").eq(i).parent().parent().remove();

Update:
interlaced deletion, endless deletion at a time:

$(".dele").click(function () {
    let arr = $(".checkboxdele")
    for (let i = arr.length - 1; i >= 0; i--) { // 
        if (arr[i].checked) {
            arr.eq(i).parent().parent().remove();
        }
    }
})

$(".checkboxdele") [I] is a dom object, not a jquery object. There is no parent method


you print out $(".checkboxdele") [I] to see what its nodes are, and then print its parent () , and you'll soon be able to locate the problem.

Menu