Reputation: 7121
I made the next jsfiddle: http://jsfiddle.net/alonshmiel/Sq5wa/4/
when the user press the backspace
key, I want to delete by the next instructions:
<li>
element: delete the <li>
and delete a <div>
element that is found in "countries" <ul>
: <div><br></div>
(every <li>
creates <div><br></div>
)I have a function that detects the backspace key:
$('#countries').keydown(function(e) {
if (e.which == 8) {
}
});
you can add li-s by add text to the ul and press the enter key
any help appreciated!
Upvotes: 2
Views: 658
Reputation: 33880
You can do it with this line :
$(window.getSelection().anchorNode).closest('li').remove();
It will get the current cursor position and delete the node if it is a li
.
Upvotes: 1