我从我的JavaScript添加HTML删除按钮与文本。我想要删除li和文本。从JavaScript删除HTML李和文本
我相信我没有正确地找到李项目将其删除。
任何帮助表示赞赏!
$("#add_btn").click(function() {
var job = $("#add_task").val().trim();
if (job.length != 0) {
$("#theList").append(
'<li>' + '<button id="remove_btn">Remove</button>' + job + '</li>'
);
} else {
window.alert("Don't add blank job");
}
});
$("#remove_btn").click(function() {
//intended to remove li and text...
$(this).next().remove(); //this is not working
});
下面是HTML:
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>To Do List</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="toDoList.js"></script>
</head>
<body>
<h1>To Do List</h1>
<label for="add_task">Add Task:</label>
<input type="text" id="add_task" name="add_task">
<br>
<button id="add_btn">
Add the task
</button>
<br>
<br>
<br>
<h2>My To Do List</h2>
<ol id="theList">
</ol>
</body>
</html>
请发表您的HTML以及。 – jrummell
@ jrummell和另外两个,不需要。 –
'