See this screenshot. I have a list of things to bring to college. I have a text input with an add button. When you type something into the input and click add, it gets added. However, when I click the close button of the item that got added, it doesn't work. The alert('test')
also doesn't show up, so I guess that the new close icon isn't responding to clicks. How can I get it to work? Here's my code:
Javascript
$("#packing_list_css .close").click(function() {
$(this).closest('li').hide();
alert('test');
});
$("#everyday_ul button").click(function() {
new_item = $("#everyday_ul :text").val();
new_item.trim();
if (new_item.length != 0)
$("<li><span class=\"close\">×</span>" + new_item + "</li>").insertBefore( "#everyday_ul :text" );
});
HTML
<p>Everyday</p>
<ul id="everyday_ul">
<% everyday.each do |item| %>
<li><span class="close">×</span> <%= item %></li>
<% end %>
<input type="text"><button class="btn btn-link">Add</button>