我從我的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和另外兩個,不需要。 –
'