我的腳本有問題。我想創建動態對象,如果我推動「創建新元素」,新的對象將被創建,但如果我推進刪除,它不起作用。爲什麼?謝謝。Jquery創建新元素,但不會刪除此元素後
<!doctype html>
<html>
<meta charset="utf-8">
<head>
\t <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
\t $(document).ready(function() {
\t
\t \t // Create new Object inside of #content
\t \t $("#wrapper > #taskbar > #create_new_element").click(function(){
\t \t \t $("#wrapper > #content").append('<div class="new_object"><p>New Object</p><a class="remove_object">Remove</a></div>');
\t \t });
\t
\t \t // Remove an Object inside of #content
\t \t $("#wrapper > #content > .new_object > .remove_object").click(function(){
\t \t \t $(this).closest('<div class="new_object"><p>New Object</p><a class="remove_object">Remove</a></div>').remove();
\t \t });
\t });
</script>
</head>
<body>
<div id="wrapper">
\t
\t \t <div id="taskbar">
\t \t \t <p id="create_new_element">Create new Element</p>
\t \t </div>
\t \t
\t \t <div id="content"></div>
</div>
</body>
的http://計算器。 com/questions/19129794/how-to-remove-an-element-that-is-added-dynamically-in-javascript –
'在動態div上添加eventlistener'看看SOs js top100的問題... –
可能重複[如何刪除在javascript中動態添加的元素](http://stackoverflow.com/questions/19129794/how-刪除一個元素,那是動態添加在javascript中) – ppasler