rwilson

msg:4433568 | 3:53 pm on Mar 26, 2012 (gmt 0) |
Basically, I want to know the correct syntax for this: .append($('<li>$('#editInput')</li>'));
|
Fotiman

msg:4433576 | 4:06 pm on Mar 26, 2012 (gmt 0) |
.append('<li>' + $('#editInput').val() + '</li>');
|
rwilson

msg:4433595 | 5:07 pm on Mar 26, 2012 (gmt 0) |
Thank you so much! I appreciate the help.
|
rwilson

msg:4433667 | 8:40 pm on Mar 26, 2012 (gmt 0) |
When I try to use the ".deleteThis" function it doesn't work on <li> tags created after page load. Is there a way I can apply the function to new <li> tags? $('#edit').submit(function() { $('#output').append('<li><span contenteditable="true">' + $('#editInput').val() + '</span><span class="deleteThis">X</span></li>'); localStorage.setItem('todoData', $('#output')); return false; }); $(".deleteThis").click(function() { alert('Handler for .deleteThis() called.'); //$("li").remove(); $(this).parent('li').hide(); }); });
|
Fotiman

msg:4433709 | 10:31 pm on Mar 26, 2012 (gmt 0) |
It doesn't work because you're attaching the handler to the click event of all elements with class "deleteThis" before you've created them in the submit function. Try this: $('#edit').submit(function() { var toggleEl = $('<span class="deleteThis">X</span>').click(function() { alert('Handler for .deleteThis() called.'); $(this).parent('li').hide(); }); $('#output').append('<li><span contenteditable="true">' + $('#editInput').val() + '</span>' + toggleEl + '</li>'); localStorage.setItem('todoData', $('#output')); return false; });
|
| Not sure if that will work, but give it a try. :)
|
|