I have the following code: Html:
<body>
<div>
<p class='Go'>
Create
</p>
<p class='Del'>
Remove
</p>
</div>
</body>
CSS:
.Go{
background-color: lime;
width:45px;
text-align: center;
}
.bad{
background-color:Red;
width: 45px;
text-align:center;
}
.Del{
background-color:pink;
width: 55px;
}
Javascript(Jquery)
$(document).ready(function(){
$('.Go').click(function(){
$('div').append("<p class='bad'>Delete</p>");
});
$('.bad').click(function(){
$(this).remove();
});
$('.Del').click(function(){
$('.bad').remove();
})
});
The idea was that every time I clicked the "create", it would add a new "delete".
Every time I clicked the "remove", all the "delete"'s would go away, and every time I clicked a "delete", that single delete would be removed.
All but the last one works. Any ideas what mistake am I making here?