referencing the id of a div

I'm trying to reference the id of a div-table row in the variable thisId . When I console.log(thisId) , it says that thisId is undefined . What am I doing wrong?

$('.deleteButton').click(function(){
    var thisId = $(this).parent().parent().id;
    for (var i = 0; i < tableData.length; i++) {
        if (tableData[i].rowValue === thisId) {
            tableData.splice(thisId, 1);
        }
    }
    $(this).parent().parent().remove();
});
}
}

HTML

"<div id='" + tableData[i].rowValue + "' class="Row">" +
                            "<div class="Cell">" +
                            "<p>" + tableData[i].textInput + "</p>" +
                        "</div>" +
                        "<div class="Cell">" +
                            "<p>" + tableData[i].perIntervalInput + "</p>" +
                        "</div>" +
                        "<div class="Cell">" +
                            "<p>" + tableData[i].radioInput + "</p>" +
                        "</div>" +
                        "<div class="Cell">" +
                            "<button class="deleteButton">Delete</button>" +
                        "</div>" +
                        "</div>"

ID是一个属性,因此可以通过attr(..)函数进行引用。

var thisId = $(this).parent().parent().attr("id");

Since you're using jQuery, you can use:

var thisId = $(this).parent().parent().attr('id');

But your HTML isn't here to show us what you're actually referencing, and whether you're referencing it properly, so there might be something else in play.

链接地址: http://www.djcxy.com/p/83310.html

上一篇: 检查点击元素的ID

下一篇: 引用div的id