I attached the delete key to document so when delete key is pressed, div gets removed. However when i’m inside a textarea, i don’t want this behavior. The delete key inside textarea should only delete text and not affect the document and deleting the div. The following is not working;
$(document).keyup(function() {
if (e.which == 46) {
$('div').remove()
}
})
A check against the type of element that triggered the event will work.
Here’s it added to your example
http://jsfiddle.net/JY46t/