我正在尝试获取已删除的 LI 元素的 ID。下面是我的代码:
// when the user wants to just trash a task compeletely
$(".ui-icon-trash").on("click", function(e) {
var id = $(this).parent("li");
// var idVal = id.getAttribute("id");
tb_show("Warning!", "#TB_inline?height=100&width=260&inlineId=divDelete", "");
e.preventDefault();
$(this).parent("li").remove();
});
问题是 id.getAttribute("id") 返回未定义。
我的 LI 属性如下所示:
<li class="ui-widget-content ui-corner-tr" id="1">
<h5 class="ui-widget-header">Task</h5>
<img src="graphics/task.png" width="96" height="72" />
Sample Task
<a href="" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
<a href="" title="Delete task" class="ui-icon ui-icon-trash">Delete task</a>
</li>
// when the user wants to just trash a task compeletely
$(".ui-icon-trash").on("click", function(e) {
var id = $(this).parent("li");
// var idVal = id.getAttribute("id");
tb_show("Warning!", "#TB_inline?height=100&width=260&inlineId=divDelete", "");
e.preventDefault();
var myVar = $(this).parent("li").attr("id");
$(this).parent("li").remove();
});
myVar 应该返回被删除元素的 ID
我是一名优秀的程序员,十分优秀!